当前位置: 首页 > 教程资源 > Windows 教程 > 正文
如何使用脚本或命令行查看 Windows 10 产品密钥

如何使用脚本或命令行查看 Windows 10 产品密钥

作者:大眼仔~旭 日期:3年前 (2020-11-22) 评论:1 条

摘要:有许多工具可以从实时系统或脱机计算机的注册表配置单元中提取产品密钥。 此外,这是一个小巧的 Vbscript,可获取当前 Windows 安装的产品密钥-无需第三方程序。 该脚本可在 Windows 7、8 和 Windows 10 上运行。以下是大眼仔旭给大家整理的查看 Windows 10 产品密钥的两种方法,希望…

有许多工具可以从实时系统或脱机计算机的注册表配置单元中提取产品密钥。 此外,这是一个小巧的 Vbscript,可获取当前 Windows 安装的产品密钥-无需第三方程序。 该脚本可在 Windows 7、8 和 Windows 10 上运行。以下是大眼仔旭给大家整理的查看 Windows 10 产品密钥的两种方法,希望可以帮助到你哦。

方法1:使用 WMI 命令行或 PowerShell

使用以下 WMI 命令行来修复 Windows 安装的产品密钥。

1
wmic path softwarelicensingservice get OA3xOriginalProductKey

此方法检索存储在计算机的 UEFI/BIOS 中的激活密钥。

请注意,您需要在提升权限/管理员命令提示符窗口中运行上述命令。

或者,如果您使用的是 PowerShell,请在管理 PowerShell 窗口中运行以下命令以了解产品密钥:

1
(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey

在某些系统中,上述命令将输出标题 OA3xOriginalProductKey 和下面的空白行,不显示任何产品密钥。 如果设备没有嵌入式激活码/产品密钥,则会发生这种情况。

如果设备具有嵌入式固件激活密钥,它将显示在输出中。 如果输出为空白,则设备没有固件嵌入式激活密钥。 大多数设计为运行 Windows 8 或更高版本的 OEM 提供的设备都将具有固件嵌入式密钥。

方法2:使用脚本

重要:请注意,以下方法只是对 DigitalProductId 注册表值进行解码以获取零售产品密钥。 使用此方法检索的密钥可以是自动生成的通用 Windows 10 密钥(对于从 Windows 7 或 Windows 8 升级为数字授权的系统)。 它也可能是您在 Windows 10 安装过程中手动输入的零售版密钥(如果您早先购买了许可证)。 因此,如果您使用的是 Windows 10,建议您优先考虑第一种方法。

将以下代码复制到记事本,并将文件另存为 GetProductKey.vbs。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Option Explicit  
 
Dim objshell,path,DigitalID, Result  
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId")
Dim ProductName,ProductID,ProductKey,ProductData
'Get ProductName, ProductID, ProductKey
ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
ProductKey = "Installed Key: " & ConvertToKey(DigitalID)  
ProductData = ProductName  & vbNewLine & ProductID  & vbNewLine & ProductKey
'Show messbox if save to a file  
If vbYes = MsgBox(ProductData  & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then
   Save ProductData  
End If
 
 
 
'Convert binary to chars
Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    'Check if OS is Windows 8
    isWin8 = (Key(66) \ 6) And 1
    Key(66) = (Key(66) And &HF7) Or ((isWin8 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  
     
    If (isWin8 = 1) Then
        keypart1 = Mid(KeyOutput, 2, Last)
        insert = "N"
        KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
        If Last = 0 Then KeyOutput = insert & KeyOutput
    End If    
     
 
    ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
   
     
End Function
'Save data to a file
Function Save(Data)
    Dim fso, fName, txt,objshell,UserName
    Set objshell = CreateObject("wscript.shell")
    'Get current user name  
    UserName = objshell.ExpandEnvironmentStrings("%UserName%")  
    'Create a text file on desktop  
    fName = "C:\Users" & UserName & "\Desktop\WindowsKeyInfo.txt"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txt = fso.CreateTextFile(fName)
    txt.Writeline Data
    txt.Close
End Function

来源:检索 Windows 产品密钥 GitHub

声明:大眼仔旭 | 本文采用署名-非商业性使用-相同方式共享 4.0 国际许可协议[CC BY-NC-SA]进行授权
文章名称:《如何使用脚本或命令行查看 Windows 10 产品密钥
文章固定链接:http://www.dayanzai.me/windows-10-key-check.html
本站资源仅供个人学习交流,请于下载后 24 小时内删除,不允许用于商业用途,否则法律问题自行承担。
转载声明
全部评论: (1条)
  1. Mr.Mirror2023-01-03 10:07 回复
    大眼哥 Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" Fix为 Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" 否则VBS执行会找不到注册表键值.

发表评论

返回顶部