MCPcopy Create free account
hub / github.com/MeisApps/pcbu-desktop / IsRunningAsAdmin

Method IsRunningAsAdmin

common/src/shell/Shell.cpp:32–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30#endif
31
32bool Shell::IsRunningAsAdmin() {
33#ifdef WINDOWS
34 BOOL isAdmin = FALSE;
35 PSID adminGroup = nullptr;
36 SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
37 if(!AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroup)) {
38 spdlog::error("AllocateAndInitializeSid failed. (Code={})", GetLastError());
39 return false;
40 }
41 if(!CheckTokenMembership(nullptr, adminGroup, &isAdmin)) {
42 spdlog::error("CheckTokenMembership failed. (Code={})", GetLastError());
43 isAdmin = FALSE;
44 }
45 if(adminGroup)
46 FreeSid(adminGroup);
47 return isAdmin;
48#else
49 return geteuid() == 0;
50#endif
51}
52
53ShellCmdResult Shell::RunCommand(const std::string &cmd) {
54 /*boost::process::child proc(boost::process::search_path("osascript"), ToDo

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected