How to write Sample Code to Retrieve the Current User Name

alhabkk

Registered User.
Local time
Today, 14:00
Joined
Sep 9, 2013
Messages
49
How to write Sample Code to Retrieve the Current User Name?

I have done for short name only and I need it full

Help me!!

Private Declare Function apiGetUserNameWindows Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserNameWindows(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
 
Not sure if this will help I get the current user name using

Environ("username")

I use this with a basic If statement to limit access to certain features or buttons
 

Users who are viewing this thread

Back
Top Bottom