VC to determine whether the process has the authority of the Administrator _c language

Source: Internet
Author: User

This article is an example of how VC determines whether a process has admin permission. Yes, returns True, otherwise false. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:
Static BOOL isadmin (void)
{
HANDLE Haccesstoken;
BYTE infobuffer[1024];
Ptoken_groups ptggroups;
DWORD dwinfobuffersize;
Psid psidadministrators;
Sid_identifier_authority siantauthority = security_nt_authority;
UINT i;
BOOL bRet = FALSE;

if (! OpenProcessToken (GetCurrentProcess (), Token_query,&haccesstoken))
return bRet;
BRet = GetTokenInformation (Haccesstoken, tokengroups, InfoBuffer, 1024, &dwinfobuffersize);
CloseHandle (Haccesstoken);
if (!bret)
return bRet;
if (! AllocateAndInitializeSid (&siantauthority,
2,
Security_builtin_domain_rid,
Domain_alias_rid_admins,
0,0,0,0,0,0,
&psidadministrators))
return FALSE;
BRet = FALSE;
Ptggroups = (ptoken_groups) InfoBuffer;
for (i=0;i<ptggroups->groupcount;i++)
if (Equalsid (psidadministrators,ptggroups->groups[i). Sid))
BRet = TRUE;
Freesid (psidadministrators);
return bRet;
}

I hope this article on the VC program for everyone to help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.