判断当前用户是否打开了UAC(Vista or Win7 OS)

BOOL IsEnableUAC()
{
 BOOL isEnableUAC = FALSE;
 OSVERSIONINFO osversioninfo;
 ZeroMemory(&osversioninfo, sizeof(osversioninfo));
 osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo);
 BOOL bSuccess = GetVersionEx(&osversioninfo);
 if (bSuccess)
 {
 // window vista or windows server 2008 or later operating system
 if ( osversioninfo.dwMajorVersion > 5 )
 {
 HKEY hKEY = NULL;
 DWORD dwType = REG_DWORD;
 DWORD dwEnableLUA = 0;
 DWORD dwSize = sizeof(DWORD);
 LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
 TEXT("SOFTWARE//Microsoft//Windows//CurrentVersion//Policies//System//"),
 0,
 KEY_READ,
 &hKEY);
 if ( ERROR_SUCCESS == status )
 {
 status = RegQueryValueEx(hKEY,
 TEXT("EnableLUA"),
 NULL,
 &dwType,
 (BYTE*)&dwEnableLUA,
 &dwSize);
 if (ERROR_SUCCESS == status)
 {
 isEnableUAC = (dwEnableLUA == 1) ? TRUE : FALSE;
 }
 RegCloseKey(hKEY);
 }
 }
 }

 return isEnableUAC;
}

你可能感兴趣的:(windows,server,OS,null,byte)