VirtualBox

Ignore:
Timestamp:
Aug 21, 2024 5:27:35 PM (5 months ago)
Author:
vboxsync
Message:

IPRT: Added RTSystemQueryNtFeatureEnabled() API to query Windows (NT) features + testcase. Also includes internal code for querying Windows registry values. bugref:10753

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/RTSystemFirmware-win.cpp

    r105766 r105786  
    5454
    5555#include "internal-r3-win.h"
     56#include "internal-r3-registry-win.h"
    5657
    5758
     
    124125
    125126    CloseHandle(hToken);
    126 
    127     return rc;
    128 }
    129 
    130 
    131 /**
    132  * Queries a DWORD value from a Windows registry key, Unicode (wide char) version.
    133  *
    134  * @returns IPRT status code.
    135  * @retval  VERR_FILE_NOT_FOUND if the value has not been found.
    136  * @param   hKey                    Registry handle to use.
    137  * @param   pwszKey                 Registry key to query \a pwszName in.
    138  * @param   pwszName                Name of the value to query.
    139  * @param   pdwValue                Where to return the actual value on success.
    140  */
    141 static int rtSystemWinRegistryGetDWORDW(HKEY hKey, LPCWSTR pwszKey, LPCWSTR pwszName, DWORD *pdwValue)
    142 {
    143     LONG lErr = RegOpenKeyExW(hKey, pwszKey, 0, KEY_QUERY_VALUE, &hKey);
    144     if (lErr != ERROR_SUCCESS)
    145         return RTErrConvertFromWin32(lErr);
    146 
    147     int rc = VINF_SUCCESS;
    148 
    149     DWORD cbType = sizeof(DWORD);
    150     DWORD dwType = 0;
    151     DWORD dwValue;
    152     lErr = RegQueryValueExW(hKey, pwszName, NULL, &dwType, (BYTE *)&dwValue, &cbType);
    153     if (lErr == ERROR_SUCCESS)
    154     {
    155         if (cbType == sizeof(DWORD))
    156         {
    157             if (dwType == REG_DWORD)
    158             {
    159                 *pdwValue = dwValue;
    160             }
    161             else
    162                 rc = VERR_WRONG_TYPE;
    163         }
    164         else
    165             rc = VERR_MISMATCH;
    166     }
    167     else
    168         rc = RTErrConvertFromWin32(lErr);
    169 
    170     RegCloseKey(hKey);
    171 
    172     return rc;
    173 }
    174 
    175 
    176 /**
    177  * Queries a DWORD value from a Windows registry key.
    178  *
    179  * @returns IPRT status code.
    180  * @retval  VERR_FILE_NOT_FOUND if the value has not been found.
    181  * @param   hKey                    Registry handle to use.
    182  * @param   pszKey                  Registry key to query \a pszName in.
    183  * @param   pszName                 Name of the value to query.
    184  * @param   pdwValue                Where to return the actual value on success.
    185  */
    186 static int rtSystemRegistryGetDWORDA(HKEY hKey, const char *pszKey, const char *pszName, DWORD *pdwValue)
    187 {
    188     PRTUTF16 pwszKey;
    189     int rc = RTStrToUtf16Ex(pszKey, RTSTR_MAX, &pwszKey, 0, NULL);
    190     if (RT_SUCCESS(rc))
    191     {
    192         PRTUTF16 pwszName;
    193         rc = RTStrToUtf16Ex(pszName, RTSTR_MAX, &pwszName, 0, NULL);
    194         if (RT_SUCCESS(rc))
    195         {
    196             rc = rtSystemWinRegistryGetDWORDW(hKey, pwszKey, pwszName, pdwValue);
    197             RTUtf16Free(pwszName);
    198         }
    199         RTUtf16Free(pwszKey);
    200     }
    201127
    202128    return rc;
     
    310236        {
    311237            DWORD dwEnabled;
    312             rc = rtSystemRegistryGetDWORDA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State",
    313                                            "UEFISecureBootEnabled", &dwEnabled);
     238            rc = RTSystemWinRegistryQueryDWORD(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State",
     239                                               "UEFISecureBootEnabled", &dwEnabled);
    314240            if (RT_SUCCESS(rc))
    315241            {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette