GetUserLogonName




Public Function GetUserLogonName() As String
'

' This will obtain the users logged on name once from the system. The

' second time it is called it returns the static 'sName' variable

'

Static sName As String
Dim lBuffLen As Long
Dim sBuffer As String
Dim lRet As Long


If Len(sName) > 0 Then
GetUserLogonName = sName
Exit Function
Else
lBuffLen = 128
sBuffer = String$(lBuffLen, vbNullChar)
lRet = GetUserName(sBuffer, lBuffLen)
If lRet < 0 Then
'

' Handle error from API here

'

Exit Function
End If
sName = Left$(sBuffer, lBuffLen - 1)
GetUserLogonName = sName
End If

End Function










( getuserlogonname.html )- by Paolo Puglisi - Modifica del 17/12/2023