以编程方式检查Windows是否使用C++; 我试图写一个C++函数,告诉用户当前使用的Windows操作系统不是激活的。

以编程方式检查Windows是否使用C++; 我试图写一个C++函数,告诉用户当前使用的Windows操作系统不是激活的。,c++,windows,authentication,activation,C++,Windows,Authentication,Activation,我发现了一个类似的问题,但这个答案需要一个UID参数。我不希望用户必须输入任何参数 如何编程检查Windows是否用C++激活?< /P> #define _WIN32_WINNT 0x600 #include <iostream> #include <windows.h> #include <slpublic.h> /*' From: C:/Windows/System32/SLMGR.vbs ' Copyright (c) Microsoft

我发现了一个类似的问题,但这个答案需要一个UID参数。我不希望用户必须输入任何参数

如何编程检查Windows是否用C++激活?< /P> <代码>

#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;
}
#包括 #包括 #包括 /*' From:C:/Windows/System32/SLMGR.vbs "版权所有(c)微软公司。版权所有。 ' 'Windows软件授权管理工具。 ' '脚本名称:slmgr.vbs ' 'WMI类名 private const ServiceClass=“软件许可服务” private const ProductClass=“软件许可产品” private const TkaLicenseClass=“软件许可令牌激活许可” private const WindowsAppId=“55c92734-d682-4d71-983e-d6ec3f16059f” */ /**使用上面的WindowsAppId检查Windows操作系统本身是否为正版**/ bool-isGenuineWindows() { //WindowsAppId 无符号字符uuid_字节[]={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; 真正的国家; UuidFromStringA(uuid_字节,&uuid); slisgenuinalocal(&uuid,&state,nullptr); 返回状态==SL_GEN_state_为真; } int main() {
std::cout由于某种原因,接受的答案在我身上失败。它总是返回false。我将留下下面的代码,以备将来使用。它从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;
}
#定义_WIN32_WINNT 0x600
#包括
#包括
#包括
#包括
#pragma注释(lib,“Slwga.lib”)
#pragma注释(lib,“Rpcrt4.lib”)
使用std::cout;
使用std::endl;
bool-isGenuineWindows()
{
GUID uid;
RPC_WSTR RPC=(RPC_WSTR)_T(“55c92734-d682-4d71-983e-d6ec3f16059f”);
UuidFromString(rpc和uid);
真正的国家;
slisgenuinalocal(&uid,&state,NULL);
返回状态==SL_GEN_state_为真;
}
int main()
{
如果(isGenuineWindows()){

cout@antman1p No.这仅在Vista+上受支持…所以Vista、Win7、Win8、Win8.1、Win10。我已经在Win10和Win8上测试过它,可以工作。我还没有在Win7上测试过它,但我100%确定它可以工作。