-
1
- #1
SBendBuckeye
Programmer
Hello All,
I am using the following code in Access97 to retrieve the WindowsNT userID from the system. Once I have the UserID, is there an equivalent function that returns a name? As an example, if the following code returns jsmith, is there anything that I could query to return John Smith, etc?
Thanks in advance for any help or suggestions!
PS. I'm trying to avoid querying the environment settings if I can avoid it.
'Windows API function declaration
Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
(ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long)
As Long
'***************************************************************************
*********
'* Retrieve User LogonID from WindowsNT using Windows API call
'***************************************************************************
*********
Public Function GetUserLoginID() As String
Dim strName As String
Dim lngWhereAt As Long
strName = Space(255) 'Required format for WIndows API call
'Non zero return value indicates an error
If WNetGetUser(vbNullString, strName, Len(strName)) Then
strName = vbNullString
Else
'Windows API returns 255 byte string with actual data delimited by
null
lngWhereAt = InStr(strName, vbNullChar)
If lngWhereAt > 0 Then
strName = Mid$(strName, 1, lngWhereAt - 1) 'Left$ doesn't always
work
End If
End If
GetUserLoginID = Trim$(strName)
End Function 'GetUserLoginID
I am using the following code in Access97 to retrieve the WindowsNT userID from the system. Once I have the UserID, is there an equivalent function that returns a name? As an example, if the following code returns jsmith, is there anything that I could query to return John Smith, etc?
Thanks in advance for any help or suggestions!
PS. I'm trying to avoid querying the environment settings if I can avoid it.
'Windows API function declaration
Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
(ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long)
As Long
'***************************************************************************
*********
'* Retrieve User LogonID from WindowsNT using Windows API call
'***************************************************************************
*********
Public Function GetUserLoginID() As String
Dim strName As String
Dim lngWhereAt As Long
strName = Space(255) 'Required format for WIndows API call
'Non zero return value indicates an error
If WNetGetUser(vbNullString, strName, Len(strName)) Then
strName = vbNullString
Else
'Windows API returns 255 byte string with actual data delimited by
null
lngWhereAt = InStr(strName, vbNullChar)
If lngWhereAt > 0 Then
strName = Mid$(strName, 1, lngWhereAt - 1) 'Left$ doesn't always
work
End If
End If
GetUserLoginID = Trim$(strName)
End Function 'GetUserLoginID