BOOL IsAdministrator() {//判断是否管理员模式
BOOL bIsElevated = FALSE;
HANDLE hToken = NULL;
UINT16 uWinVer = LOWORD(GetVersion());
uWinVer = MAKEWORD(HIBYTE(uWinVer),LOBYTE(uWinVer));
if (uWinVer < 0x0600))//不是VISTA、Windows7
return(FALSE);
if (OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken)) {
struct {
DWORD TokenIsElevated;
} /*TOKEN_ELEVATION*/te;
DWORD dwReturnLength = 0;
if (GetTokenInformation(hToken,/*TokenElevation*/(_TOKEN_INFORMATION_CLASS)20,&te,sizeof(te),&dwReturnLength)) {
if (dwReturnLength == sizeof(te))
bIsElevated = te.TokenIsElevated;
}
CloseHandle( hToken );
}
return bIsElevated;
}
时间: 2024-10-26 12:10:12