vc判断当前用户是否具有administrator 权限代码
Posted 早上起来洗澡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vc判断当前用户是否具有administrator 权限代码相关的知识,希望对你有一定的参考价值。
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; }
以上是关于vc判断当前用户是否具有administrator 权限代码的主要内容,如果未能解决你的问题,请参考以下文章
Linux脚本练习之script013-判断当前用户对指定参数文件,是否不可读并且不可写。
VC++检测防火墙是否开启判断程序是否加入防火墙白名单(附源码)