Skip to content

Instantly share code, notes, and snippets.

@linquize
Created October 29, 2012 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linquize/3973764 to your computer and use it in GitHub Desktop.
Save linquize/3973764 to your computer and use it in GitHub Desktop.
UAC MFC
BOOL IsAdmin()
{
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
// Initialize SID.
if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup))
return false;
// Check whether the token is present in admin group.
BOOL IsInAdminGroup = FALSE;
if (!CheckTokenMembership(NULL, AdministratorsGroup, &IsInAdminGroup))
IsInAdminGroup = FALSE;
// Free SID and return.
FreeSid(AdministratorsGroup);
return IsInAdminGroup;
}
((CButton *)this->GetDlgItem(IDOK))->SetShield(!IsAdmin());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment