C++ GetUserName()

时间:2023-03-09 00:32:32
C++ GetUserName()

关于函数“GetUserName()”,参见:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx

IDE: Code::Blocks

操作系统:Windows 7 x64

 #include <windows.h>
#include <stdio.h> using namespace std; int main()
{
CHAR cUserNameBuffer[];
DWORD dwUserNameSize = ; /* Retrieves the name of the user associated with the current thread. */
if(GetUserName(cUserNameBuffer, &dwUserNameSize)) {
printf("The user name is %s \n", cUserNameBuffer);
}
else {
printf("Get user name failed with error: %lu \n", GetLastError());
} return ;
}