Combining fOSUserName() and ShowUserRosterMultipleUsers()

A

azu_daioh

I have the ShowUserRosterMultipleUsers() to identify the users
currently logged on to the database -- and I have the fOSUserNam() to
identify the logon ID.

But I need to be able to see the actual persons' userID corresponding
to the computer name being provided to me the the
ShowUserRosterMultipleUsers() function.

Does anyone know if this could be done?

When I run the ShowUserRosterMultipleUsers fuction, I only get the
Computer Name but the Logon_ID is all "admin" -- I use to maintain a
list of all the computer names and username but I can't keep up with
all the changes and moving around of our users.

Here's the code I got from microsoft:
Sub ShowUserRosterMultipleUsers()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i, j As Long

Set cn = CurrentProject.Connection

' The user roster is exposed as a provider-specific schema rowset
' in the Jet 4.0 OLE DB provider. You have to use a GUID to
' reference the schema, as provider-specific schemas are not
' listed in ADO's type library for schema rowsets

Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
, "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

'Output the list of all users in the current database.

Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
"", rs.Fields(2).Name, rs.Fields(3).Name

While Not rs.EOF
Debug.Print rs.Fields(0), rs.Fields(1), _
rs.Fields (2), rs.Fields(3)
rs.MoveNext
Wend

End Sub

----

And the code from Access Web:

' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If

End Function
'******************** Code End **************************


So how do I modify the show user function to actually display the
username?

Thank you,
 
D

Douglas J. Steele

There's no connection between fOSUserName and the computer name (which is
what ShowUserRosterMultipleUsers gives), so there's no point even trying to
link them.

I think you can use the NetWkstaGetInfo and NetWkstaUserEnum API functions
to get the information of who's logged onto a given computer, but I've never
tried, so I don't know what permission you need on the network. Randy Birch
has a sample at
http://vbnet.mvps.org/code/network/netwkstagetinfousername.htm

Obligatory warning: Randy's site is aimed at VB programmers. There are some
significant differences between the controls available for forms in VB and
in Access, so not all of his samples will port directly into Access. At a
quick glance, there are several things in that sample that won't work in
Access. For one thing, he's using a control array, which Access doesn't
support. All the stuff with TabArray and SendMessage in the Form_Load event
relates to making the list box have columns. It won't work in Access, but
columns in an Access list box are trivial. Hopefully, though, you'll be able
to figure out what the code's doing, and perhaps be able to incorporate it
into your application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top