'Declarations - Public or Private
' Form Level, Module Level
Public Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
Dim lngInstr As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn <> 0 Then
sBuffer = Left$(sBuffer, lSize)
lngInstr = InStr(sBuffer, Chr$(0))
If lngInstr > 0 Then
sBuffer = _
Left$(sBuffer, lngInstr - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
GetWindowsLoginUserID = ""
End If
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.