【问题标题】:Programmatically Check if Windows is Activated with C++以编程方式检查 Windows 是否已使用 C++ 激活
【发布时间】:2017-09-14 23:07:47
【问题描述】:

我正在尝试编写一个 C++ 函数,它会告诉用户他们当前使用的 Windows 操作系统是否已激活。

我发现了一个类似的问题Programmatically check if Windows 7 is activated,但这个答案需要一个 UID 参数。我不希望用户输入任何参数。

如何以编程方式检查 Windows 是否使用 C++ 激活?

【问题讨论】:

    标签: c++ windows authentication activation


    【解决方案1】:
    #define _WIN32_WINNT 0x600
    
    #include <iostream>
    #include <windows.h>
    #include <slpublic.h>
    
    
    /*'
    From: C:/Windows/System32/SLMGR.vbs
    
    
    ' Copyright (c) Microsoft Corporation. All rights reserved.
    '
    ' Windows Software Licensing Management Tool.
    '
    ' Script Name: slmgr.vbs
    '
    ' WMI class names
    private const ServiceClass                            = "SoftwareLicensingService"
    private const ProductClass                            = "SoftwareLicensingProduct"
    private const TkaLicenseClass                         = "SoftwareLicensingTokenActivationLicense"
    private const WindowsAppId                            = "55c92734-d682-4d71-983e-d6ec3f16059f"
    */
    
    
    /** Use the WindowsAppId above to check if Windows OS itself is Genuine. **/
    bool isGenuineWindows()
    {
        //WindowsAppId
        unsigned char uuid_bytes[] = {0x35, 0x35, 0x63, 0x39, 0x32, 0x37, 0x33, 0x34, 0x2d, 0x64, 0x36,
                                    0x38, 0x32, 0x2d, 0x34, 0x64, 0x37, 0x31, 0x2d, 0x39, 0x38, 0x33,
                                    0x65, 0x2d, 0x64, 0x36, 0x65, 0x63, 0x33, 0x66, 0x31, 0x36, 0x30,
                                    0x35, 0x39, 0x66};
    
        GUID uuid;
        SL_GENUINE_STATE state;
    
        UuidFromStringA(uuid_bytes, &uuid);
        SLIsGenuineLocal(&uuid, &state, nullptr);
        return state == SL_GEN_STATE_IS_GENUINE;
    }
    
    int main()
    {
        std::cout<<isGenuineWindows();
        return 0;
    }
    

    链接:librpcrt4.alibslwga.a

    【讨论】:

    • @antman1p 否。这仅在 Vista+ 上受支持。所以 Vista、Win7、Win8、Win8.1、Win10。我已经在Win10和Win8上测试过,可以。我还没有在 Win7 上测试过,但我 100% 肯定它会工作。
    【解决方案2】:

    由于某种原因,我接受的答案失败了。它总是返回错误。我将保留下面的代码以供将来使用。它从 Windows-Vista 开始对我有用,到现在 Windows-10 版本 20H2。

    #define _WIN32_WINNT 0x600
    #include <iostream>
    #include <windows.h>
    #include <slpublic.h>
    #include <tchar.h>
    #pragma comment(lib, "Slwga.lib")
    #pragma comment(lib, "Rpcrt4.lib")
    
    using std::cout;
    using std::endl;
    
    bool isGenuineWindows()
    {
        GUID uid;
        RPC_WSTR rpc = (RPC_WSTR)_T("55c92734-d682-4d71-983e-d6ec3f16059f");
        UuidFromString(rpc, &uid);
        SL_GENUINE_STATE state;
        SLIsGenuineLocal(&uid, &state, NULL);
        return state == SL_GEN_STATE_IS_GENUINE;
    }
    
    int main()
    {
        if (isGenuineWindows()) {
            cout << "Licensed" << endl;
        }
        else {
            cout << "Unlicensed" << endl;
        }
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-17
      • 2015-02-18
      • 1970-01-01
      • 2012-04-10
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多