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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Users NT or W2k login id

Status
Not open for further replies.

JONBOY74

Technical User
Sep 11, 2001
36
0
0
US
How can I return a users NT or W2k login id to a form

Many Thanks

Jon
 
Paste this API declaration at top of module:

Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long


Public Function GetCurrentNTLogin() As String
On Error GoTo ErrGetCurrentNTLogin
Dim lLengthUserName As Long
Dim sUserName As String
Dim lResult As Long


' Use the GetUserName API to find out who is currently logged onto
' this system. Preset the length of the string to hold the
' returned user name from the "GetUserName" API.
lLengthUserName = 255
sUserName = Space(lLengthUserName)

' Call GetUserName to find out who is logged onto this system.
lResult = GetUserName(sUserName, lLengthUserName)

' Return value of zero means the call failed; test for this before
' continuing.
If (lResult = 0) Then
sUserName = Environ("USERNAME")
End If

GetCurrentNTLogin = TrimBuffer(sUserName)

Exit Function
'*** Error Trap ***
ErrGetCurrentNTLogin:
Err.Raise Err.Number, "GetCurrentNTLogin:" & MODULE_NAME & vbCrLf & Err.Source, Err.Description
End Function


Hope this helps,
Cheers,
Grant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top