Platform SDK: Windows System Information
GetUserNameEx
The GetUserNameEx function retrieves the name of the user or other security principal associated with the calling thread. You can specify the format of the returned name.
If the thread is impersonating a client, GetUserNameEx returns the name of the client.
BOOLEAN GetUserNameEx(
EXTENDED_NAME_FORMAT NameFormat,
LPTSTR lpNameBuffer,
PULONG nSize
);
Parameters
NameFormat
[in] Format of the name. This parameter is a value from the EXTENDED_NAME_FORMAT enumeration type. It cannot be NameUnknown.
lpNameBuffer
[out] Pointer to a buffer that receives the name in the specified format. The buffer must include space for the terminating null character.
nSize
[in, out] On input, this variable specifies the size of the lpNameBuffer buffer, in TCHARs. If the function is successful, the variable receives the number of TCHARs copied to the buffer, not including the terminating null character. If lpNameBuffer is too small, the function fails and GetLastError returns ERROR_MORE_DATA. This parameter receives the required buffer size, including the terminating null character.
Return Values
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the user name is not available in the specified format, the error is ERROR_NONE_MAPPED. If the domain controller is not available to perform the lookup, the error is ERROR_NO_SUCH_DOMAIN.
Requirements
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Unsupported.
Unicode: Implemented as Unicode and ANSI versions.
Header: Declared in Secext.h; include Security.h.
Library: Use Secur32.lib.
See Also
System Information Overview, System Information Functions, EXTENDED_NAME_FORMAT, GetUserName
|