Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using this code in VBA to get NT LogonID - can I get name also 2

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
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


 

Hi

do a web search on "vb netusergetinfo" & you will find plenty of examples on how to do this

regards

Rob

 
How about
Environ("computername")
Environ("username")
These work fine,
--Jim
 
The environment strings are readily resettable from DOS, and so provide an unreliable method of getting any permanent info


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top