mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2024-11-23 22:30:56 +01:00
feat(util): Add func to check if running as admin user
This has been a source of common error in the past. It is known that most, or even all, games run into various issues when not run with elevated privileges.
This commit is contained in:
parent
e2a6410461
commit
06317d63e7
@ -1,7 +1,55 @@
|
||||
#include <windows.h>
|
||||
#define LOG_MODULE "util-proc"
|
||||
|
||||
#include <windows.h>
|
||||
#include <winnt.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
bool proc_is_running_as_admin_user()
|
||||
{
|
||||
SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
|
||||
PSID sid;
|
||||
BOOL res;
|
||||
BOOL is_admin;
|
||||
|
||||
res = AllocateAndInitializeSid(
|
||||
&authority,
|
||||
2,
|
||||
SECURITY_BUILTIN_DOMAIN_RID,
|
||||
DOMAIN_ALIAS_RID_ADMINS,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&sid);
|
||||
|
||||
if (!res) {
|
||||
log_warning(
|
||||
"Failed to allocate memory for is admin check: %lX",
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
is_admin = false;
|
||||
|
||||
res = CheckTokenMembership(NULL, sid, &is_admin);
|
||||
|
||||
if (!res) {
|
||||
log_warning(
|
||||
"Failed to check admin group membership: %lX", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
FreeSid(sid);
|
||||
|
||||
return is_admin;
|
||||
}
|
||||
|
||||
void proc_terminate_current_process(uint32_t exit_code)
|
||||
{
|
||||
HANDLE hnd;
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
bool proc_is_running_as_admin_user();
|
||||
|
||||
void proc_terminate_current_process(uint32_t exit_code);
|
Loading…
Reference in New Issue
Block a user