首页 > 代码库 > Windows判断是否为管理员
Windows判断是否为管理员
// IsUserAdminTest.cpp : Defines the entry point for the console application.//#include <Windows.h>#include <tchar.h>#include <iostream>BOOL IsUserAdmin();int _tmain(int argc, _TCHAR* argv[]){ printf_s("%d\n",IsUserAdmin()); return 0;}BOOL IsUserAdmin(){ BOOL b = FALSE; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup = NULL; b = AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if(b) { HANDLE hThreadUserToken = NULL; if (!::OpenThreadToken(::GetCurrentThread(), TOKEN_READ,//must have TOKEN_QUERY false, &hThreadUserToken)) { if (!CheckTokenMembership( hThreadUserToken, AdministratorsGroup, &b)) { b = FALSE; } if (AdministratorsGroup) { FreeSid(AdministratorsGroup); } } if (hThreadUserToken) { CloseHandle(hThreadUserToken); } } return(b);}
Windows判断是否为管理员
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。