VC斷定過程能否具有administrator權限的辦法。本站提示廣大學習愛好者:(VC斷定過程能否具有administrator權限的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是VC斷定過程能否具有administrator權限的辦法正文
本文實例講述了VC斷定過程能否具有admin權限的辦法。是的話前往TRUE,不然為FALSE。分享給年夜家供年夜家參考。詳細完成辦法以下:
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;
}
願望本文所述對年夜家的VC法式設計有所贊助。