mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-14 15:55:30 +00:00
Create username.c
This commit is contained in:
parent
a6f48c2709
commit
b42a41fb2f
20
system/username.c
Normal file
20
system/username.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <Lmcons.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
int wmain(void) {
|
||||||
|
|
||||||
|
wchar_t username[UNLEN+1];
|
||||||
|
DWORD len = sizeof(username) / sizeof(wchar_t);
|
||||||
|
|
||||||
|
int r = GetUserNameW(username, &len);
|
||||||
|
|
||||||
|
if (r == 0) {
|
||||||
|
wprintf(L"Failed to get username %ld", GetLastError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wprintf(L"User name: %ls\n", username);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user