#include "ba1701.h" #define WIN32_LEAN_AND_MEAN #include bool run_as_admin() { bool yes = true; TOKEN_ELEVATION_TYPE elevationType = (TOKEN_ELEVATION_TYPE)0; // N/A for < Vista OSVERSIONINFO VerInfo = { 0 }; VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); ::GetVersionEx(&VerInfo); if (VerInfo.dwMajorVersion >= 6) // If Vista or newer, { HANDLE hToken = NULL; // read elevation type BOOL bOK = ::OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken); if (bOK) { DWORD infoLen; yes = ::GetTokenInformation(hToken, TokenElevationType, // type of info to retrieve &elevationType, // receives return value sizeof(elevationType), &infoLen) != 0; // receives returned length } } return yes; }