2.1.25.31 GetUserName


Description

The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system.

Syntax

BOOL GetUserName( LPSTR lpBuffer, DWORD * nSize )

Parameters

lpBuffer
[input] char buffer storage name
nSize
[modify] On input, specifies the size of the buffer. On output, receives the number of chars copied to the buffer including null terminator.

Return

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

If the function fails, the return value is zero.

Examples

EX1

int GetUserName_ex1()
{
    char szUserName[MAX_PATH];
    DWORD dwSize = MAX_PATH;
    if( GetUserName(szUserName, &dwSize) )
        printf("User Name is %s\n", szUserName);
    else
        printf("Error calling GetUserName\n");
    return 1;
}

Remark

See Also

GetComputerName

Header to Include

origin.h

Reference