Get User Name
Posted: 2002-06-01
By: ArchiveBot
Viewed: 63
Filed Under:
No attachments for this post
Returns the current user name using a dll call
Original Author: Matthew Grove
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
Code
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
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.