Private Const UNKNOWN = _
"(Value Unknown Because System Call Failed)"
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize _
As Long) As Long
Public Function GetCurrentUserName() As String
Dim l As Long
Dim sUser As String
sUser = Space$(255)
l = GetUserName(sUser, 255)
'strip null terminator
If l <> 0 Then
GetCurrentUserName = Left(sUser, InStr(sUser, Chr(0)) - 1)
Else
Err.Raise Err.LastDllError, , _
"A system call returned an error code of " _
& Err.LastDllError
End If
End Function
Private Sub Form_Load()
MsgBox GetCurrentUserName()
End Sub
Hi chirawa,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept xSinbad's comment(s) as an answer.
chirawa, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
SpideyModCommented:
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Username in NT msgbox environ("UserName")
or
API
Declare Function GetUserName Lib "advapi32" Alias "GetUserNameA" (ByVal strName As String, ByRef dwLength As Long) As Long
intLen = 50
strUserID = Space(intLen + 1)
GetUserName strUserID, intLen
strUserID = Left(strUserID, intLen - 1)
msgbox strUserID
(TimCottee - Q_20219899)
http://www.vbcode.com/asp/showsn.asp?theID=1075
http://www.vbcode.com/asp/showsn.asp?theID=3795