campo-sirio/ba/ba1701.cpp

28 lines
906 B
C++

#include "ba1701.h"
#define WIN32_LEAN_AND_MEAN
#define STRICT
#include <windows.h>
bool run_as_admin()
{
bool yes = true;
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)
{
TOKEN_ELEVATION_TYPE elevationType = (TOKEN_ELEVATION_TYPE)0; // N/A for < Vista
DWORD infoLen = 0;
yes = ::GetTokenInformation(hToken, TokenElevationType, // type of info to retrieve
&elevationType, // receives return value
sizeof(elevationType), &infoLen) != 0; // receives returned length
::CloseHandle(hToken);
}
}
return yes;
}