GetUserName()

Purpose
The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system
 
Library Transcribed by Date of page Updated on
AdvAPI32.dll J.Paris 25.04.06  
 
Restrictions on use
Requires Windows NT 3.1 or later; Requires Windows 95 or later
 
Declare 32-bit

declare function GetUserNameA Lib "advapi32.dll"

    (User As String, i As Integer) As Logical

Required Type definition
 none
 
Parameters

lpBuffer

Points to the buffer to receive the null-terminated string containing the user’s logon name. If this buffer is not large enough to contain the entire user name, the function fails.

 

nSize

Pointer to a DWORD that, on input, specifies the maximum size, in characters, of the buffer specified by the lpBuffer parameter. If this buffer is not large enough to contain the entire user name, the function fails. If the function succeeds, it will place the number of characters copied to the buffer into the DWORD that nSize points to.

 
Return value

If the function succeeds, the return value is nonzero, and the variable pointed to by nSize contains the number of characters copied to the buffer specified by lpBuffer, including the terminating null character.

If the function fails, the return value is zero.

 
Example

'inspired by graham@businessgeographics.co.uk

 

declare function GetUserNameA Lib "advapi32.dll" (User As String, i As Integer) As Logical

declare function GetUserName() As String

 

note "User name is "+chr$(10)+getusername()

 

'*******************************************************************************

Function GetUserName() As String

'*******************************************************************************

Dim User As String

Dim i As Integer

i=254

User=String$(i," ")

If GetUserNameA(User,i) Then

    GetUserName=RTrim$(User)

  Else

    GetUserName=""

End If

End Function

 
Comments
 
 
See also