【问题标题】:VBScript to return Windows Product KeyVBScript 返回 Windows 产品密钥
【发布时间】:2015-05-15 22:23:39
【问题描述】:

我需要一个 VBScript 来返回 Windows 产品密钥。我在网上找到了一些 VBScript,但这些是特定于某些 Windows 版本的。是否有适用于 Windows 7 - Windows 8.1 的 VBScript?

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    你可以试试this code:

    const HKEY_LOCAL_MACHINE = &H80000002
    
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    strValueName = "DigitalProductId"
    strComputer = "."
    dim iValues()
    
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
      strComputer & "\root\default:StdRegProv")
    oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues
    
    Dim arrDPID
    arrDPID = Array()
    For i = 52 to 66
      ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
      arrDPID( UBound(arrDPID) ) = iValues(i)
    Next
    ' <--- Create an array to hold the valid characters for a microsoft Product Key --->
    Dim arrChars
    arrChars = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")
    
    ' <--- The clever bit !!! (Decrypt the base24 encoded binary data) --->
    For i = 24 To 0 Step -1
      k = 0
      For j = 14 To 0 Step -1
        k = k * 256 Xor arrDPID(j)
        arrDPID(j) = Int(k / 24)
        k = k Mod 24
      Next
      strProductKey = arrChars(k) & strProductKey
      ' <--- add the "-" between the groups of 5 Char --->
      If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
    Next
    strFinalKey = strProductKey
    
    ' <--- This part of the script displays operating system Information and the license Key --->
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colOperatingSystems
      strOS   = objOperatingSystem.Caption
      strBuild   = objOperatingSystem.BuildNumber
      strSerial   = objOperatingSystem.SerialNumber
      strRegistered  = objOperatingSystem.RegisteredUser
    Next
    
    Set wshShell=CreateObject("wscript.shell")
    strPopupMsg = strOS & vbNewLine & vbNewLine
    strPopupMsg = strPopupMsg & "Build Number:  " & strBuild & vbNewLine
    strPopupMsg = strPopupMsg & "PID:  " & strSerial & vbNewLine & vbNewLine
    strPopupMsg = strPopupMsg & "Registered to:  " & strRegistered & vbNewLine & vbNewLine & vbNewLine
    strPopupMsg = strPopupMsg & "Your Windows Product Key is:" & vbNewLine & vbNewLine & strFinalKey
    strPopupTitle = "Microsoft Windows License Information"
    wshShell.Popup strPopupMsg,,strPopupTitle,vbCancelOnly+vbinformation
    

    【讨论】:

    • @Hackoo 请不要在没有适当归属的情况下发布其他人的代码。
    • 你认为我可以用它来将计算机名称和 Windows 产品密钥回显到文件 \\server\share\list.txt,这样我就可以将其设置为登录脚本,它会在 list.txt 中生成一个列表?
    猜你喜欢
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2012-07-24
    • 2021-05-14
    • 2017-09-12
    • 2011-05-08
    相关资源
    最近更新 更多