VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get User Name

by Matthew Grove (2 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Returns the current user name using a dll call

Code Returns
The current user that is logged on
API Declarations
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long

Rate Get User Name

Function GetUser()
 ' This function uses a windows dll to query the registry automatically ti return the user name
 Dim sBuffer As String
 Dim lSize As Long
 ' Parameters for the dll declaration are set
 sBuffer = Space$(255)
 lSize = Len(sBuffer)
 Call GetUserName(sBuffer, lSize)   ' Call the declared dll function
If lSize > 0 Then
 GetUser = Left$(sBuffer, lSize)   ' Remove empty spaces
Else
 GetUser = vbNullString   ' Return empty if no user is found
End If
End Function

Download this snippet    Add to My Saved Code

Get User Name Comments

No comments have been posted about Get User Name. Why not be the first to post a comment about Get User Name.

Post your comment

Subject:
Message:
0/1000 characters