MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / IsRunningAsAdministrator

Function IsRunningAsAdministrator

libcommonutil/commonutil.cpp:189–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189bool IsRunningAsAdministrator(bool *pIsReallyAdmin)
190{
191 BOOL isAdmin = FALSE;
192 HANDLE hToken = NULL;
193
194 if (pIsReallyAdmin)
195 *pIsReallyAdmin = false;
196
197 // Open the process token
198 if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
199 {
200 // Create a SID for the Administrators group
201 PSID administratorsGroup = NULL;
202 SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
203 if (AllocateAndInitializeSid(&ntAuthority, 2,
204 SECURITY_BUILTIN_DOMAIN_RID,
205 DOMAIN_ALIAS_RID_ADMINS,
206 0, 0, 0, 0, 0, 0,
207 &administratorsGroup))
208 {
209 // Check if the token has the Administrators group SID
210 CheckTokenMembership(hToken, administratorsGroup, &isAdmin);
211 FreeSid(administratorsGroup);
212 }
213 CloseHandle(hToken);
214 }
215
216 if (isAdmin)
217 {
218 if (pIsReallyAdmin)
219 *pIsReallyAdmin = true;
220
221 return true;
222 }
223 else
224 {
225 return IsProcessElevated();
226 }
227}

Callers 1

CcppcryptfsAppMethod · 0.85

Calls 1

IsProcessElevatedFunction · 0.85

Tested by

no test coverage detected