다음을 통해 공유


HWREQCHK API 예제

참고

일부 정보는 상용 출시 전에 실질적으로 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.

중요

이 항목에 설명된 기능은 Windows Insider Preview 시험판 버전에서 사용할 수 있습니다. 이러한 기능이 표시되는 가장 빠른 버전은 Windows Insider Preview 버전 10.0.25289입니다.

HWREQCHK API에 대한 이러한 예제는 하드웨어 디바이스에 대한 정보를 가져오는 데 활용하는 방법과 특정 버전의 Windows 11 이상에 대해 결정된 Windows 업그레이드 자격을 보여 줍니다.

GetHardwareRequirementSystemInfo API 예제

아래 예제에서는 Windows 하드웨어 요구 사항 평가 엔진에서 사용하는 것과 동일한 정보인 GetHardwareRequirementSystemInfo를 호출하여 디바이스 시스템 정보를 가져오는 방법을 보여 줍니다. 컨텍스트는 EvaluateHardwareRequirement 함수의 또는 false 응답을 고려한 true 디바이스 시스템 정보를 보고하기 위해 "업그레이드할 수 있나요?" 도구에서 사용할 수 있다는 것입니다.

#include <windows.h>
#include <objbase.h>
#include <wil/resource.h>
#include <hwreqchkapi.h>
#define PRINT_TRUE_FALSE(cond) (cond ? L"TRUE" : L"FALSE")   

HRESULT
GetHardwareRequirementSystemInfoExample()
/*++
    Routine Description:
        Get the Hardware Requirements System Info that is used to evaluate against the requirements
    Example:
        Demonstrates GetHardwareRequirementSystemInfo API
    Arguments:
        N/A
    Return Value:
        HRESULT - S_OK or a FAILED HRESULT if unsuccessful getting the defined list of hardware requirements
--*/
{
    HWREQCHK_DEVICE_HARDWARE_SYSINFO sysinfo{};
    HRESULT result = GetHardwareRequirementSystemInfo(&sysinfo);
    if (SUCCEEDED(result))
    {
        wprintf(L"     SSE2 Processor Support: %ls\n", PRINT_TRUE_FALSE(sysinfo.SSE2ProcessorSupport));
        wprintf(L"       NX Processor Support: %ls\n", PRINT_TRUE_FALSE(sysinfo.NXProcessorSupport));
        wprintf(L"          PrefetchW Support: %ls\n", PRINT_TRUE_FALSE(sysinfo.PrefetchWSupport));
        wprintf(L" CompareExchange128 Support: %ls\n",
                                                PRINT_TRUE_FALSE(sysinfo.CompareExchange128Support));
        wprintf(L"           LahfSahf Support: %ls\n", PRINT_TRUE_FALSE(sysinfo.LahfSahfSupport));
        wprintf(L"             CPU Core Count: %lu\n", sysinfo.CpuCoreCount);
        wprintf(L"         SecureBoot Capable: %ls\n", PRINT_TRUE_FALSE(sysinfo.SecureBootCapable));
        wprintf(L"                TPM Version: %lu\n", sysinfo.TpmVersion   );
        wprintf(L"                    CPU Mhz: %lu\n", sysinfo.CpuMhz);
        wprintf(L"                      RamMB: %lu\n", sysinfo.RamMB);
        wprintf(L"           SystemDiskSizeMB: %lu\n", sysinfo.SystemDiskSizeMB);
        wprintf(L"               Architecture: %lu\n", sysinfo.Architecture);
        wprintf(L"                 CPU Vendor: %lu\n", sysinfo.CpuVendor      );
        wprintf(L"                 CPU Family: %lu\n", sysinfo.CpuFamily);
        wprintf(L"                  CPU Model: %lu\n", sysinfo.CpuModel);
        wprintf(L"               CPU Stepping: %lu\n", sysinfo.CpuStepping);
        wprintf(L"   ArmV81 Processor Support: %ls\n", PRINT_TRUE_FALSE(sysinfo.ArmV81ProcessorSupport));
        wprintf(L"                   Platform: %lu\n", sysinfo.Platform   );
        wprintf(L"                   IsServer: %ls\n", PRINT_TRUE_FALSE(sysinfo.IsServer  ));
        wprintf(L"              Lockdown Mode: %lu\n", sysinfo.LockdownMode);
        wprintf(L"                 Product OS: %lu\n", sysinfo.ProductOS  );
        wprintf(L"               Product Name: %ls\n", sysinfo.ProductName);
        wprintf(L"             Processor Name: %ls\n", sysinfo.ProcessorName);
    }
    else
    {
        wprintf(L"Failed calling GetHardwareRequirementSystemInfo. Error:0x%.8x\n", result);
    }
    return result;
}

EvaluateHardwareRequirement API 예제

이 예제에서는 EvaluateHardwareRequirement를 사용하는 방법을 보여 줍니다. 디바이스 하드웨어 시스템 속성을 쿼리하여 정의된 하드웨어 요구 사항에 대해 평가하는 함수입니다. EvaluateHardwareRequirementExample 예제 메서드는 평가할 하드웨어 요구 사항에 대한 정보를 포함하는 HWREQCHK_DEVICE_HARDWARE_REQUIREMENT 구조를 허용합니다. 다른 예제에서는 개발자가 구조체의 내용을 입력하여 평가할 요구 사항을 결정하는 다양한 방법을 보여 줍니다.

#include <windows.h>
#include <objbase.h>
#include <wil/resource.h>
#include <hwreqchkapi.h>

HRESULT
EvaluateHardwareRequirementExample(
    _In_ const HWREQCHK_DEVICE_HARDWARE_REQUIREMENT& deviceHardwareRequirement)
/*++
    Routine Description:
        Evaluate the specific hardware requirement using the information supplied in the HWREQCHK_DEVICE_HARDWARE_REQUIREMENT structure
    Example:
        Demonstrates EvaluateHardwareRequirement API
    Arguments:
        deviceHardwareRequirement - Specifies the specific device hardware requirement structure that is used to invoke the EvaluateHardwareRequirement API
    Return Value:
        HRESULT - S_OK or a Failed HRESULT if unsuccessful invoking the EvaluateHardwareRequirement API
--*/
{
    //
    // Automatically free HWREQCHK_DEVICE_HARDWARE_EVALUATION (via CoTaskMemFree) 
    // objects when it goes out of scope. See WIL (https://github.com/Microsoft/wil/wiki).
    //
    wil::unique_cotaskmem_array_ptr<HWREQCHK_DEVICE_HARDWARE_EVALUATION>
                                            deviceHardwareRequirementEvaluations;
    BOOL evaluationResult = FALSE;
    static const std::map<const std::wstring, const std::wstring> constraintRuleMapping =
    {
        { L"SSE2ProcessorSupport", L"Processor must support the SSE2 instruction set"} ,
        { L"NXProcessorSupport", L"Processor must support data execution prevention" },
        { L"CompareExchange128", L"Processor must support the CMPXCHG16B instruction also referred to as CompareExchange128" },
        { L"LahfSahfSupport", L"Processor must support the LAHF and SAHF instructions" },
        { L"PrefetchWSupport", L"Processor must support the PrefetchW instructions" },
        { L"CpuCores", L"The minimum number of CPU cores that must exist on the device" },
        { L"CpuFms", L"TPM must be version 2.0 exactly(no higher, no lower)" },
        { L"Tpm", L"TPM must be version 2.0 exactly" },
        { L"UefiSecureBoot", L"Secure boot must be supported on the device"},
        { L"Memory", L"The minimum amount of memory in MB that must exist on the device" },
        { L"IotMemory", L"The minimum amount of memory in MB that must exist on the device" },
        { L"ServerMemory", L"The minimum amount of memory in MB that must exist on the device" },
        { L"SystemDriveSize", L"The minimum amout of total system disk size" },
        { L"IotSystemDriveSize", L"The minimum amout of total system disk size" },
        { L"CpuFms", L"The CPU must be a supported Family, Model and Stepping (FMS) processor signature" },
        { L"BlockedByHomeSkuSModeStateSV", L"SMode must be disabled unless the OS SKU is a 'Home'SKU" }
    };

    HRESULT result = EvaluateHardwareRequirement(
        &deviceHardwareRequirement,
        &evaluationResult,
        &deviceHardwareRequirementEvaluations,
        deviceHardwareRequirementEvaluations.size_address<ULONG>());
    if (FAILED(result))
    {
        wprintf(L"The requirement failed the EvaluateHardwareRequirement API. Error:0x%.8x\n", result);
    }
    else
    {
        //
        // On Success, the 'evaluationResult' variable will either be TRUE (evaluation succeeded)
        // or it will be FALSE (evaluation failed).
        //
        if (evaluationResult != FALSE)
        {
            wprintf(L"The hardware requirement evaluation succeeded. The device does meet the hardware requirements\n");        
        }
        else
        {
            wprintf(L"The hardware requirement evaluation did not pass. The device does not meet the hardware requirements.\n");
        }

        // Loop through each constraint evaluation performed
        for (const auto& deviceHardwareRequirementEvaluation : deviceHardwareRequirementEvaluations)
        {    
            auto findConstraint = constraintRuleMapping.find(deviceHardwareRequirementEvaluation.RuleName);
            std::wstring constraintDescription = L"Constraint Not Found";
            if (findConstraint != constraintRuleMapping.end())
            {
                constraintDescription = findConstraint->second;
            }

            // Display the Rules that were evaluated as part of the requirements.
            // NOTE: RuleName is a non-localized value coming from the internally defined JSON contents.
            wprintf(L"\tConstraint Name: %-64ls Succeeded: %-8ls\n\t\tDescription: %ls\n",
                deviceHardwareRequirementEvaluation.RuleName,
                deviceHardwareRequirementEvaluation.Succeeded ? L"TRUE" : L"FALSE",
                constraintDescription.c_str());
        }

    if (evaluationResult == FALSE)
        {
            // The device failed to meet the hardware requirements, dump the system
            // info by calling the other example GetHardwareRequirementSystemInfoExample,
            // which calls the API GetHardwareRequirementSystemInfo and dumps the contents.
            GetHardwareRequirementSystemInfoExample();
        }
    }
    return result;
}

GetLatestHardwareRequirement API 예제

아래 예제에서는 GetLatestHardwareRequirement를 사용하는 방법을 보여 줍니다. 지정된 HWREQCHK_PRODUCT_TYPE 열거형 값에 대한 최신 하드웨어 요구 사항을 쿼리하고 반환하는 함수입니다. 호출이 성공하면 HWREQCHK_DEVICE_HARDWARE_REQUIREMENT 구조체의 내용을 위의 EvaluateHardwareRequirement 예제에 전달합니다.

#include <windows.h>
#include <objbase.h>
#include <wil/resource.h>
#include <hwreqchkapi.h>

HRESULT
GetLatestHardwareRequirementExample(
    _In_ HWREQCHK_PRODUCT_TYPE productType)
/*++
    Routine Description:
        Get the latest hardware requirement defined and then use 
        the information supplied in the HWREQCHK_DEVICE_HARDWARE_REQUIREMENT
        to evaluate hardware requirements against it.
    Example:
        Demonstrates the use of the GetLatestHardwareRequirement API. If successful, the
        EvaluateHardwareRequirementExample method is invoked to ‘evaluate’
        the latest hardware requirement.
    Arguments:
        productType - A valid HWREQCHK_PRODUCT_TYPE enumeration value to get the latest hardware requirement
    Return Value:
        HRESULT - S_OK or a FAILED HRESULT if unsuccessful getting the defined list of hardware requirements
--*/
{
    HWREQCHK_DEVICE_HARDWARE_REQUIREMENT deviceHardwareRequirement {};

    // Get the currently defined latest hardware requirement for the product type value
    // specified in the productEnum variable.
    HRESULT result = GetLatestHardwareRequirement(productType, &deviceHardwareRequirement);
    if (FAILED(result))
    {
        wprintf(L"The call to GetLatestHardwareRequirement failed. Error:0x%.8x\n", result);
    }
    else
    {
        // 
        // Use the default hardware requirement returned from the GetLatestHardwareRequirement API
        // to verify the hardware device requirements for the latest defined OS
        // by calling the EvaluateHardwareRequirementExample method.
        //
        result = EvaluateHardwareRequirementExample(deviceHardwareRequirement);
    }

    return result;
}

GetHardwareRequirements API 예제

이 예제에서는 GetHardwareRequirements 를 사용하여 정의되고 평가할 수 있는 하드웨어 요구 사항의 전체 목록을 가져오는 방법을 보여 줍니다. 이 예제에서는 예제 메서드에 제공된 인수와 일치하는 특정 요구 사항이 발견될 때까지 사용할 수 있는 각 요구 사항을 열거합니다.

#include <windows.h>
#include <objbase.h>
#include <wil/resource.h>
#include <hwreqchkapi.h>

HRESULT
GetHardwareRequirementsExample(
    _In_ HWREQCHK_TARGET_RELEASE targetRelease,
    _In_ HWREQCHK_PRODUCT_TYPE productType)
/*++
    Routine Description:
        Gets all of the defined hardware requirements and evaluates one or more of the requirements
    Example:
        Demonstrates the use of the GetHardwareRequirements API. If successful and a
        match is found for the supplied requirement & product enum arguments, then the  
        EvaluateHardwareRequirementExample method is invoked to ‘evaluate’
        the hardware requirement.
    Arguments:
        targetRelease  - A valid HWREQCHK_TARGET_RELEASE enumeration value 
                         used to filter the list of returned requirement(s)
        productType    – A valid HWREQCHK_PRODUCT_TYPE enumeration value 
                         used to filter the list of returned requirement(s)
    Return Value:
        HRESULT        - S_OK or a FAILED HRESULT if unsuccessful getting the 
                         defined list of hardware requirements
--*/
{
    const HRESULT errNotFound = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);

    //
    // Automatically free HWREQCHK_DEVICE_HARDWARE_REQUIREMENT (via CoTaskMemFree) 
    // objects when it goes out of scope. See WIL (https://github.com/Microsoft/wil/wiki).
    //
    wil::unique_cotaskmem_array_ptr<HWREQCHK_DEVICE_HARDWARE_REQUIREMENT> deviceHardwareRequirements;

    // Get the currently defined hardware requirements
    HRESULT result = GetHardwareRequirements(
                             &deviceHardwareRequirements, 
                             deviceHardwareRequirements.size_address<ULONG>());
    if (FAILED(result))
    {
        wprintf(L"The call to GetHardwareRequirements failed. Error:0x%.8x\n", result);
    }
    else
    {
        for (const auto& deviceHardwareRequirement : deviceHardwareRequirements)
        {
            result = errNotFound;

            // Look for a requirement matching the TargetRelease and ProductType enumeration values
            if (deviceHardwareRequirement.TargetRelease == targetRelease &&
                deviceHardwareRequirement.ProductType == productType)
            {
                // We found a match. Now evaluate the requirement by
                // calling the EvaluateHardwareRequirementExample method
                result = EvaluateHardwareRequirementExample(deviceHardwareRequirement);
                if (FAILED(result))
                {
                    wprintf(L"Error invoking the example method EvaluateHardwareRequirementExample\n");
                }
                break  ;
            }
        }
    }

    if (result == errNotFound  )
    {
        wprintf(L"Unable to locate a matching target-release '%d' and product-type '%d'\n",    
                targetRelease, producttype);
    }

    return result;
}

HWREQCHK API 개요

HWREQCHK API 함수

WIL(Windows 구현 라이브러리) wiki