找回密码
 加入
搜索
查看: 97|回复: 9

[AU3基础] Powershell代码转AU3的问题

[复制链接]
发表于 2025-3-10 20:11:55 | 显示全部楼层 |阅读模式
求转成AU3,谢谢

function PrintDigitalLicenseStatus {
        try {
                . InitializeDigitalLicenseCheck
                $ComObj = New-Object -Com EditionUpgradeManagerObj.EditionUpgradeManager
        } catch {
                return $FALSE
        }

        $parameters = 1, $null

        if ([EUM.IEUM].GetMethod("AcquireModernLicenseForWindows").Invoke($ComObj, $parameters)) {
                return $FALSE
        }

        $dwReturnCode = $parameters[1]
        [bool]$bDigitalLicense = $FALSE

        $bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1))
        CONOUT ("    IsDigitalLicense={0}" -f (BoolToWStr $bDigitalLicense))

        return $TRUE
}

发表于 2025-3-10 21:32:47 | 显示全部楼层
找了一圈,没搜到这个对象的资料
 楼主| 发表于 2025-3-10 22:53:46 | 显示全部楼层
haijie1223 发表于 2025-3-10 21:32
找了一圈,没搜到这个对象的资料

这是C语言代码:
#include <windows.h>
#include <objbase.h>
#include <ocidl.h>
#include <stdio.h>
#include "clic.h"

#define BoolToWStr(bVal) ((bVal) ? L"TRUE" : L"FALSE")

BOOL InitializeDigitalLicenseCheck(IEditionUpgradeManager **m_IEditionUpgradeManager) {
    GUID guidEditionUpgradeManager = {
        0x17CCA47D, 0xDAE5, 0x4E4A,
        {0xAC, 0x42, 0xCC, 0x54, 0xE2, 0x8F, 0x33, 0x4A}
    };

    GUID guidIEditionUpgradeManager = {
        0xF2DCB80D, 0x0670, 0x44BC,
        {0x90, 0x02, 0xCD, 0x18, 0x68, 0x87, 0x30, 0xAF}
    };

    if(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))
        return FALSE;

    if(CoCreateInstance(
        &guidEditionUpgradeManager,
        0,
        CLSCTX_INPROC_SERVER,
        &guidIEditionUpgradeManager,
        (PVOID*)m_IEditionUpgradeManager
    )) {
        return FALSE;
    }

    return TRUE;
}

BOOL PrintStateData() {
    PWSTR pwszStateData = 0;
    UINT cbSize = 0;

    if(SLGetWindowsInformation(
        L"Security-SPP-Action-StateData",
        NULL,
        &cbSize,
        (PBYTE*)&pwszStateData
    )) {
        return FALSE;
    }

    for(INT i = 0; i < (cbSize / 2); i++) {
        if(pwszStateData[i] == L';')
            pwszStateData[i] = L'\n';
    }

    wprintf(L"%ws\n", pwszStateData);

    LocalFree(pwszStateData);
    return TRUE;
}

BOOL PrintLastActivationHRresult() {
    PDWORD pdwLastHResult = 0;
    UINT cbSize = 0;

    if(SLGetWindowsInformation(
        L"Security-SPP-LastWindowsActivationHResult",
        NULL,
        &cbSize,
        (PBYTE*)&pdwLastHResult
    )) {
        return FALSE;
    }

    wprintf(L"LastActivationHResult=0x%08x\n", *pdwLastHResult);

    LocalFree(pdwLastHResult);
    return TRUE;
}

BOOL PrintDigitalLicenseStatus() {
    IEditionUpgradeManager *m_IEditionUpgradeManager;
    DWORD dwReturnCode = 0;
    BOOL bDigitalLicense = FALSE;

    if(!InitializeDigitalLicenseCheck(&m_IEditionUpgradeManager))
        return FALSE;

    if(m_IEditionUpgradeManager->lpVtbl->AcquireModernLicenseForWindows(
        m_IEditionUpgradeManager,
        1,
        &dwReturnCode
    )) {
        return FALSE;
    }

    bDigitalLicense = (dwReturnCode != 1 && dwReturnCode <= INT_MAX);
    wprintf(L"DigitalLicense=%ws\n", BoolToWStr(bDigitalLicense));

    return TRUE;
}

BOOL PrintSubscriptionStatus() {
    SUBSCRIPTIONSTATUS *pStatus;
    DWORD dwSupported = 0;

    if(SLGetWindowsInformationDWORD(L"ConsumeAddonPolicySet", &dwSupported))
        return FALSE;

    wprintf(L"SubscriptionSupportedEdition=%ws\n", BoolToWStr(dwSupported));

    if(ClipGetSubscriptionStatus(&pStatus))
        return FALSE;

    wprintf(L"SubscriptionEnabled=%ws\n", BoolToWStr(pStatus->dwEnabled));

    if(pStatus->dwEnabled == 0) {
        LocalFree(pStatus);
        return TRUE;
    }

    wprintf(L"SubscriptionSku=%d\n", pStatus->dwSku);
    wprintf(L"SubscriptionState=%d\n", pStatus->dwState);

    LocalFree(pStatus);
    return TRUE;
}

BOOL PrintIsWindowsGenuine() {
    DWORD dwGenuine = 0;
    PCWSTR ppwszGenuineStates[] = {
        L"SL_GEN_STATE_IS_GENUINE",
        L"SL_GEN_STATE_INVALID_LICENSE",
        L"SL_GEN_STATE_TAMPERED",
        L"SL_GEN_STATE_OFFLINE",
        L"SL_GEN_STATE_LAST"
    };

    if(SLIsWindowsGenuineLocal(&dwGenuine))
        return FALSE;

    if(dwGenuine < 5) {
        wprintf(L"IsWindowsGenuine=%ws\n", ppwszGenuineStates[dwGenuine]);
    } else {
        wprintf(L"IsWindowsGenuine=%d\n", dwGenuine);
    }

    return TRUE;
}

int WINAPI wWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    PWSTR pCmdLine,
    int nCmdShow
) {
    BOOL bError = FALSE;

    if(!PrintStateData())
        bError = TRUE;

    if(!PrintLastActivationHRresult())
        bError = TRUE;

    if(!PrintDigitalLicenseStatus())
        bError = TRUE;

    if(!PrintSubscriptionStatus())
        bError = TRUE;

    if(!PrintIsWindowsGenuine())
        bError = TRUE;

    exit(bError);
}
发表于 7 天前 | 显示全部楼层
zbezj 发表于 2025-3-10 22:53
这是C语言代码:

需要完整项目,缺少 "clic.h"
 楼主| 发表于 7 天前 | 显示全部楼层
haijie1223 发表于 2025-3-11 08:12
需要完整项目,缺少 "clic.h"

这是源代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 7 天前 | 显示全部楼层

如此这般?
#NoTrayIcon
#AutoIt3Wrapper_UseX64 = y 
Global Const $CLSD_EditionUpgradeManager = "{17CCA47D-DAE5-4E4A-AC42-CC54E28F334A}"
Global Const $IID_IEditionUpgradeManager = "{F2DCB80D-0670-44BC-9002-CD18688730AF}"
Global Const $TaskList = 'InitializeWindow HRESULT(HWND);' & _
                'UpdateOperatingSystem HRESULT(PTR;DWORD);' & _
                'ShowProductKeyUI HRESULT(DWORD);' & _
                'UpdateOperatingSystemWithParams HRESULT(PTR;BOOL;BOOL;BOOL;BOOL;DWORD);' & _
                'AcquireModernLicenseForWindows HRESULT(DWORD;DWORD*);' & _
                'AcquireModernLicenseWithPreviousId HRESULT(PTR;DWORD*);'
ConsoleWrite(PrintDigitalLicenseStatus() & @CRLF)
Func PrintDigitalLicenseStatus()
        Local $om_IEditionUpgradeManager = ObjCreateInterface($CLSD_EditionUpgradeManager, $IID_IEditionUpgradeManager, $TaskList)
        If Not IsObj($om_IEditionUpgradeManager) Then Return False
        Local $dwReturnCode = 0
        If $om_IEditionUpgradeManager.AcquireModernLicenseForWindows(1, $dwReturnCode) = 0 Then Return $dwReturnCode <> 1 And $dwReturnCode < 2147483647
        Return False
EndFunc   ;==>PrintDigitalLicenseStatus
 楼主| 发表于 6 天前 | 显示全部楼层

执行的结果不对,并且不知道为啥执行上面代码后还会弹出一个系统设置的窗口。这是c代码编译后的exe,它的执行结果是对的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 6 天前 | 显示全部楼层
zbezj 发表于 2025-3-12 20:01
执行的结果不对,并且不知道为啥执行上面代码后还会弹出一个系统设置的窗口。这是c代码编译后的exe,它的 ...

代码更新了,6楼自己测试
 楼主| 发表于 6 天前 | 显示全部楼层
haijie1223 发表于 2025-3-12 21:48
代码更新了,6楼自己测试

这次好像对了,多谢大佬
发表于 前天 18:22 | 显示全部楼层
发哥还是一如即往的热心
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2025-3-18 21:39 , Processed in 0.097503 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表