[CPP]View PlainCopyprint?
- /************************************************************************/
- /* Function Description: Determine whether there are administrator permissions
- /* Parameter: None
- /* Return value: True is returned successfully, otherwise false is returned
- /* By:koma 2009.07.28 23:30
- /************************************************************************/
- BOOL ISAdmin ()
- {
- HANDLE Haccesstoken;
- BYTE * InfoBuffer = new byte[1024];
- Ptoken_groups ptggroups;
- DWORD dwinfobuffersize;
- PSID psidadministrators;
- Sid_identifier_authority siantauthority = security_nt_authority;
- if (! OpenProcessToken (GetCurrentProcess (), Token_query,&haccesstoken))
- {
- Delete InfoBuffer;
- return FALSE;
- }
- if (! GetTokenInformation (haccesstoken,tokengroups,infobuffer,1024,&dwinfobuffersize))
- {
- Delete InfoBuffer;
- CloseHandle (Haccesstoken);
- return FALSE;
- }
- CloseHandle (Haccesstoken);
- if (! AllocateAndInitializeSid (&siantauthority,
- 2,
- Security_builtin_domain_rid,
- Domain_alias_rid_admins,
- 0,0,0,0,0,0,
- &psidadministrators))
- {
- Delete InfoBuffer;
- return FALSE;
- }
- Ptggroups = (ptoken_groups) InfoBuffer;
- For (UINT i = 0; i < ptggroups->groupcount; i++)
- {
- if (Equalsid (psidadministrators,ptggroups->groups[i). Sid))
- {
- Freesid (psidadministrators);
- Delete InfoBuffer;
- return TRUE;
- }
- }
- return FALSE;
- }
http://blog.csdn.net/wangningyu/article/details/4389546
VC judge the current user has no administrator permissions (with the Equalsid API function to determine whether the admin in a group SID)