将二进制文件注册到PowerShell中的Windows密钥

将二进制文件注册到PowerShell中的Windows密钥,powershell,registry,Powershell,Registry,我试图从一个设备中提取一个可读的win10密钥,其中的密钥是数字的 意思是: 获取WmiObject-查询“从SoftwareLicensingService中选择*”.OA3xOriginalProductKey 没有结果 我使用reg query HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion/v DigitalProductId,但我当然会得到reg\U二进制输出 有人知道如何将其转换为普通的win10密钥吗 Edit:Readable=

我试图从一个设备中提取一个可读的win10密钥,其中的密钥是数字的

意思是: 获取WmiObject-查询“从SoftwareLicensingService中选择*”.OA3xOriginalProductKey 没有结果

我使用reg query HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion/v DigitalProductId,但我当然会得到reg\U二进制输出

有人知道如何将其转换为普通的win10密钥吗

Edit:Readable=通常在标签上找到的正常windows产品密钥,例如:9JNB6-GWD4G-JQHC7-*****-*****

编辑2:工作的VBS脚本

    Const KeyOffset = 52
    Dim isWin10, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    'Check if OS is Windows 10
    isWin10 = (Key(66) \ 6) And 1
    Key(66) = (Key(66) And &HF7) Or ((isWin10 And 2) * 4)
    i = 24
    Maps = "BCDFGHJKMPQRTVWXY2346789"
    Do
           Current= 0
        j = 14
        Do
           Current = Current* 256
           Current = Key(j + KeyOffset) + Current
           Key(j + KeyOffset) = (Current \ 24)
           Current=Current Mod 24
            j = j -1
        Loop While j >= 0
        i = i -1
        KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
        Last = Current
    Loop While i >= 0
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = "N"
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)

下面是PowerShell中的函数。希望它能满足您的需求:

function Get-ProductKey {
    [cmdletbinding()]
    Param (
        [parameter(ValueFromPipeLine = $true, ValueFromPipeLineByPropertyName = $true)]
        [Alias("IPAddress", "Server")]
        [string[]]$Computername = $env:COMPUTERNAME
    )
    Begin {   
        $map = "BCDFGHJKMPQRTVWXY2346789" 
    }
    Process {
        foreach ($Computer in $Computername) {
            if (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) {
                Write-Warning "Computer $Computer is unreachable"
                continue
            }
            # try and determine if this is a 64 or 32 bit machine
            try {
                $OS = Get-WmiObject -ComputerName $Computer -Class Win32_OperatingSystem -ErrorAction Stop                
            } 
            catch {
                Write-Warning "Could not retrieve OS version from computer $Computer"
                continue
            }
            # try and read the registry
            try {
                $remoteReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
                $valueName = if ([int]($OS.OSArchitecture -replace '\D') -eq 64) { 'DigitalProductId4' } else { 'DigitalProductId' }
                $value = $remoteReg.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue($valueName)[0x34..0x42]
                $productKey = for ($i = 24; $i -ge 0; $i--) { 
                    $k = 0 
                    for ($j = 14; $j -ge 0; $j--) { 
                        $k = ($k * 256) -bxor $value[$j] 
                        $value[$j] = [math]::Floor([double]($k/24)) 
                        $k = $k % 24 
                    }
                    # output one character to collect in the $productKey array
                    $map[$k]
                    # output a hyphen
                    if (($i % 5) -eq 0 -and $i -ne 0) { "-" } 
                }
                # reverse the array
                [array]::Reverse($productKey)
                # output the ProductKey as string
                $productKey -join ''
            } 
            catch {
                Write-Warning "Could not read registry from computer $Computer"
            }        
            finally {
                if ($remoteReg) { $remoteReg.Close() }
            }
        } 
    }
}


Get-ProductKey

下面是PowerShell中的函数。希望它能满足您的需求:

function Get-ProductKey {
    [cmdletbinding()]
    Param (
        [parameter(ValueFromPipeLine = $true, ValueFromPipeLineByPropertyName = $true)]
        [Alias("IPAddress", "Server")]
        [string[]]$Computername = $env:COMPUTERNAME
    )
    Begin {   
        $map = "BCDFGHJKMPQRTVWXY2346789" 
    }
    Process {
        foreach ($Computer in $Computername) {
            if (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) {
                Write-Warning "Computer $Computer is unreachable"
                continue
            }
            # try and determine if this is a 64 or 32 bit machine
            try {
                $OS = Get-WmiObject -ComputerName $Computer -Class Win32_OperatingSystem -ErrorAction Stop                
            } 
            catch {
                Write-Warning "Could not retrieve OS version from computer $Computer"
                continue
            }
            # try and read the registry
            try {
                $remoteReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
                $valueName = if ([int]($OS.OSArchitecture -replace '\D') -eq 64) { 'DigitalProductId4' } else { 'DigitalProductId' }
                $value = $remoteReg.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue($valueName)[0x34..0x42]
                $productKey = for ($i = 24; $i -ge 0; $i--) { 
                    $k = 0 
                    for ($j = 14; $j -ge 0; $j--) { 
                        $k = ($k * 256) -bxor $value[$j] 
                        $value[$j] = [math]::Floor([double]($k/24)) 
                        $k = $k % 24 
                    }
                    # output one character to collect in the $productKey array
                    $map[$k]
                    # output a hyphen
                    if (($i % 5) -eq 0 -and $i -ne 0) { "-" } 
                }
                # reverse the array
                [array]::Reverse($productKey)
                # output the ProductKey as string
                $productKey -join ''
            } 
            catch {
                Write-Warning "Could not read registry from computer $Computer"
            }        
            finally {
                if ($remoteReg) { $remoteReg.Close() }
            }
        } 
    }
}


Get-ProductKey

您使用的是哪个Windows版本?Microsoft Windows 10 Pro 10.0.18362生成18362 slmgr/dli返回什么?3V66T?作为初学者,请参见@mklement0上的答案:@zetzke,那么它确实值得查看注册表。这是某种24进制编码。字母表为BCDFGHJKMPQRTVWXY2346789。现在,您知道了纯文本的一部分,您可以检查算法。您使用的是哪个Windows版本?Microsoft Windows 10 Pro 10.0.18362 Build 18362 slmgr/dli返回什么?3V66T?作为初学者,请参见@mklement0上的答案:@zetzke,那么它确实值得查看注册表。这是某种24进制编码。字母表为BCDFGHJKMPQRTVWXY2346789。现在你知道了明文的一部分,你有一些东西可以检查你的算法。现在它返回了一些与原始脚本不同的东西,但那可能就是我:我来玩玩it@zetzke这可能是因为您正在从reg属性DigitalProductId读取值,但对于64位机器,您应该从DigitalProductID4获取它,此时它返回的内容与原始脚本不同,但这可能就是我:我将使用it@zetzke这可能是因为您正在从reg属性DigitalProductId读取值,但对于64位计算机,您应该从DigitalProductId4获取该值