0
点赞
收藏
分享

微信扫一扫

Qt 判断以管理员身份运行

bool isRunningAsAdmin()
 {
     BOOL runningAsAdmin = false;
     PSID adminGroupSid = NULL;    // allocate and initialize a SID of the administrators group.
     SID_IDENTIFIER_AUTHORITY NtAuthority = { SECURITY_NT_AUTHORITY };
     if (AllocateAndInitializeSid(
         &NtAuthority,
         2,
         SECURITY_BUILTIN_DOMAIN_RID,
         DOMAIN_ALIAS_RID_ADMINS,
         0, 0, 0, 0, 0, 0,
         &adminGroupSid))
     {
         // determine whether the SID of administrators group is enabled in
         // the primary access token of the process.
         CheckTokenMembership(NULL, adminGroupSid, &runningAsAdmin);
     }    if (adminGroupSid)
     {
         FreeSid(adminGroupSid);
     }    return runningAsAdmin;
 }

举报

相关推荐

0 条评论