Support fetching the windows username
This commit is contained in:
parent
dbee7d9741
commit
73f9859eed
@ -1,4 +1,7 @@
|
|||||||
#include "nt.hpp"
|
#include "nt.hpp"
|
||||||
|
|
||||||
|
#include <lmcons.h>
|
||||||
|
|
||||||
#include "string.hpp"
|
#include "string.hpp"
|
||||||
|
|
||||||
namespace utils::nt
|
namespace utils::nt
|
||||||
@ -310,7 +313,8 @@ namespace utils::nt
|
|||||||
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
|
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
|
||||||
auto* const command_line = GetCommandLineA();
|
auto* const command_line = GetCommandLineA();
|
||||||
|
|
||||||
CreateProcessA(self.get_path().generic_string().data(), command_line, nullptr, nullptr, false, NULL, nullptr, current_dir,
|
CreateProcessA(self.get_path().generic_string().data(), command_line, nullptr, nullptr, false, NULL, nullptr,
|
||||||
|
current_dir,
|
||||||
&startup_info, &process_info);
|
&startup_info, &process_info);
|
||||||
|
|
||||||
if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread);
|
if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) CloseHandle(process_info.hThread);
|
||||||
@ -322,4 +326,16 @@ namespace utils::nt
|
|||||||
TerminateProcess(GetCurrentProcess(), code);
|
TerminateProcess(GetCurrentProcess(), code);
|
||||||
_Exit(code);
|
_Exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get_user_name()
|
||||||
|
{
|
||||||
|
char username[UNLEN + 1];
|
||||||
|
DWORD username_len = UNLEN + 1;
|
||||||
|
if (!GetUserNameA(username, &username_len))
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(username, username_len - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,4 +252,6 @@ namespace utils::nt
|
|||||||
|
|
||||||
void relaunch_self();
|
void relaunch_self();
|
||||||
__declspec(noreturn) void terminate(uint32_t code = 0);
|
__declspec(noreturn) void terminate(uint32_t code = 0);
|
||||||
|
|
||||||
|
std::string get_user_name();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user