campo-sirio/ba/ba1701.cpp
guy 20fc8e1492 Aggiunto controllo di permessi di amministratore ad installazione
git-svn-id: svn://10.65.10.50/branches/R_10_00@22667 c028cbd2-c16b-5b4b-a496-9718f37d4682
2012-06-07 15:56:38 +00:00

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;
}