C++ GetUserName()

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

 

IDE: Code::Blocks

操作系统:Windows 7 x64

 1 #include <windows.h>
 2 #include <stdio.h>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     CHAR cUserNameBuffer[256];
 9     DWORD dwUserNameSize = 256;
10 
11     /* Retrieves the name of the user associated with the current thread. */
12     if(GetUserName(cUserNameBuffer, &dwUserNameSize)) {
13         printf("The user name is %s \n", cUserNameBuffer);
14     }
15     else {
16         printf("Get user name failed with error: %lu \n", GetLastError());
17     }
18 
19     return 0;
20 }

 

posted @ 2018-01-03 11:27  heismk  阅读(3278)  评论(0编辑  收藏  举报