The following code supplies the login name of the user that's logged onto the PC. Copy it into a module and call the GetUserName_TSB function.
Declare Function TSB_API_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public prompt As String
Public Function GetUserName_TSB() As String
On Error GoTo error_handler
Dim lngLen As Long
Dim strBuf As String
Const MaxUserName = 255
strBuf = Space(MaxUserName)
lngLen = MaxUserName
If CBool(TSB_API_GetUserName(strBuf, lngLen)) Then
GetUserName_TSB = Left$(strBuf, lngLen - 1)
Else
GetUserName_TSB = ""
End If
Exit Function
error_handler:
Error_Recorder
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.