Hi everybody
How can I get the Windows NT Login of the current user in my app?
Fzz
Printable View
Hi everybody
How can I get the Windows NT Login of the current user in my app?
Fzz
I always found the GetUserName() API call worked fine for me (there are other calls you can use).
Paste the following code into a form :
option Explicit
private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (byval lpBuffer as string, nSize as Long) as Long
private Sub Form_Load()
Dim sBuffer as string
Dim lRet as Long
Dim sUserName as string
'
' Fill the buffer with char(0)
'
sBuffer = string$(255, vbNullChar)
lRet = GetUserName(sBuffer, 255)
If lRet = 1 then
sUserName = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
else
sUserName = "Unknown - error"
End If
MsgBox sUserName
End Sub
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb