BOOL IsAdministrator()
{
BOOL bIsElevated = FALSE;
HANDLE hToken = NULL;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
DWORD dwReturnLength = 0;
TOKEN_ELEVATION te;
if (GetTokenInformation(hToken,(_TOKEN_INFORMATION_CLASS)TokenElevation, &te, sizeof(te), &dwReturnLength)) {
if (dwReturnLength == sizeof(te))
bIsElevated = te.TokenIsElevated;
}
CloseHandle(hToken);
}
return bIsElevated;
}
if (IsAdministrator())
{
//AfxMessageBox(_T("IsAdministrator true"));
}
else
{
AfxMessageBox(_T("Please run with administrator privileges."));
return FALSE;
}