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