VC判断进程是否具有administrator权限 VC判断进程是否具有administrator权限的方法
人气:3想了解VC判断进程是否具有administrator权限的方法的相关内容吗,在本文为您仔细讲解VC判断进程是否具有administrator权限的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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;
}
{
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程序设计有所帮助。
加载全部内容