-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathlib1.c
27 lines (23 loc) · 820 Bytes
/
lib1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <windows.h>
#include <stdio.h>
#include <lmcons.h> // For UNLEN
BOOL printUsername() {
// Buffer to store the username
WCHAR username[UNLEN + 1]; // UNLEN is the maximum length of a username
DWORD username_len = sizeof(username) / sizeof(username[0]); // Size of the buffer
// Call GetUserNameW to retrieve the username
// This causes advapi32.dll to delay load sspicli.dll
if (GetUserNameW(username, &username_len)) {
wprintf(L"Username: %s\n", username);
}
else {
wprintf(L"Error retrieving username. Error code: %lu\n", GetLastError());
return 1;
}
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_ATTACH) {
printUsername();
}
}