Created
October 29, 2012 14:12
-
-
Save linquize/3973764 to your computer and use it in GitHub Desktop.
UAC MFC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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