#include <windows.h> //调用GetTokenInformation函数,获取TOKEN_ELEVATION结构体信息,通过结构体中的TokenIsElevated字段就能判断出来 bool IsRunasAdmin(){ bool bElevated = false; HANDLE hToken = NULL; // Get current process token if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) return FALSE; TOKEN_ELEVATION tokenEle; DWORD dwRetLen = 0; // Retrieve token elevation information if (GetTokenInformation(hToken, TokenElevation, &tokenEle, sizeof(tokenEle), &dwRetLen)){ if (dwRetLen == sizeof(tokenEle)){ bElevated = tokenEle.TokenIsElevated; } } CloseHandle(hToken); return bElevated; }