首页 > Windows开发 > 详细

Get your Windows product key from a script

时间:2014-02-12 02:05:28      阅读:642      评论:0      收藏:0      [点我收藏+]

The product key is located in the registry under

HKLM\Software\Microsoft\Windows NT\CurrentVersion

It is the value named: DigitalProductId

If you look at it, you will realize it is encrypted:

 

That is what his script takes care of. It reverses the simple XOR encryption and turns that numeric mess into a readable product key.

 

cscript serial.vbs

 

 

save the following code to serial.vbs

bubuko.com,布布扣
****************************************** Script Usage: Get Windows Product Key ** http://www.intelliadmin.com           ** Revision 8/15/2012                    ******************************************

Constants for our registry query
const HKEY_LOCAL_MACHINE = &H80000002 
sRegistryKeyName = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
sRegistryValueName = "DigitalProductId"

function GetProductKey
    Get the raw product key data 
    dim pValues()
    Set poRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    poRegistry.GetBinaryValue HKEY_LOCAL_MACHINE,sRegistryKeyName,sRegistryValueName,pValues

    Dim sArrayPID
    sArrayPID = Array()

    In that data, positions 52-66 contain our product id info
    We copy to an array so we can decrypt

    For i = 52 to 66
        Increase our array size by one
        ReDim Preserve sArrayPID( UBound(sArrayPID) + 1 )
        Insert our value into the end if the array
        sArrayPID(UBound(sArrayPID)) = pValues(i)
    Next

    Consants for our product key
    Dim sProductKeyChars
    sProductKeyChars = 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")

    For i = 24 To 0 Step -1
        k = 0
        For j = 14 To 0 Step -1
            k = k * 256 Xor sArrayPID(j)
            sArrayPID(j) = Int(k / 24)
            k = k Mod 24
        Next
        sProductKey = sProductKeyChars(k) & sProductKey
        Adds the - between the key sections
        if i Mod 5 = 0 And i <> 0 Then sProductKey = "-" & sProductKey
    Next
    GetProductKey = sProductKey
end function

function GetOSVersion
    Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") 
    for each System in SystemSet 
        GetOSVersion = Trim(System.Caption) & " (" & System.Version & ")"
    next 
end function 

wscript.echo GetOSVersion & ", " & GetProductKey
bubuko.com,布布扣

 

 

reference:

http://www.intelliadmin.com/index.php/2012/08/get-your-windows-product-key-from-a-script/

Get your Windows product key from a script

原文:http://www.cnblogs.com/zyip/p/3545020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!