Jump to content

Windows CD Key


blakel
 Share

Recommended Posts

Here is a function I translated from a vbs script I found somewhere. It was likely translated from Magic Jelly Bean Keyfinder.

It allows one to recover the CD key from the windows registry for reinstall, license auditing, etc.

I have only tested it with WinXP 32-bit SP3.

It will likely work with 2k on, but not sure.

I also suspect the same algorithm will work with office and other M$ products.

Func GetWXPCDKey($remotePC = ".")
 Local $dpi = RegRead("\\" & $remotePC & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId")
 $dpi = StringMid(String($dpi),107,32)
 Local $ha[16]
 For $i = 0 To 15
  $ha[$i] = Number("0x" & StringMid($dpi,($i*2)+1,2) ) 
 Next
 Local $table[24]
 $table [0] = "B"
 $table [1] = "C"
 $table [2] = "D"
 $table [3] = "F"
 $table [4] = "G"
 $table [5] = "H"
 $table [6] = "J"
 $table [7] = "K"
 $table [8] = "M"
 $table [9] = "P"
 $table [10] = "Q"
 $table [11] = "R"
 $table [12] = "T"
 $table [13] = "V"
 $table [14] = "W"
 $table [15] = "X"
 $table [16] = "Y"
 $table [17] = "2"
 $table [18] = "3"
 $table [19] = "4"
 $table [20] = "6"
 $table [21] = "7"
 $table [22] = "8"
 $table [23] = "9"

 Local $key = ""
 For $i = 1 To 25
  Local $a = 0
  For $j = 15 To 0 Step -1
   Local $b = BitOr($a * 256,$ha[$j])
   $a = Mod($b,24)
   $ha[$j] = $b / 24
  Next
  $key = $table[$a] & $key
 Next
 Return StringLeft($key,5) & "-" & StringMid($key,6,5) & "-" & StringMid($key,11,5) & "-" & StringMid($key,16,5) & "-" & StringRight($key,5)
EndFunc

Example:

$pc = InputBox("Get CD Key","Name/IP: ")
MsgBox(0,GetWXPProductName($pc) & " " & GetWXPVer($pc),"CDKey: " & GetWXPCDKey($pc) )

Func GetWXPProductName($remotePC = ".")
 Return RegRead("\\" & $remotePC & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName")
EndFunc

Func GetWXPVer($remotePC = ".")
 Return RegRead("\\" & $remotePC & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","CurrentVersion")
EndFunc

Hope you find it useful.

Link to comment
Share on other sites

I hope you don't mind, I took the liberty to update your code a little.

Func GetWXPCDKey($remotePC = ".")
    Local $dpi = RegRead("\\" & $remotePC & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")
    If @error Then Return SetError(1, 0, "")
    Local $table = StringSplit("BCDFGHJKMPQRTVWXY2346789", "", 2)
    Local $a, $b, $key = "", $ha[16]
    For $i = 0 To 15
        $ha[$i] = BinaryMid($dpi, ($i + 53), 1)
    Next
    For $i = 0 To 24
        $a = 0
        For $j = 15 To 0 Step -1
            $b = BitOR($a * 256, $ha[$j])
            $a = Mod($b, 24)
            $ha[$j] = $b / 24
        Next
        If (Not Mod($i, 5)) And $i Then $key = "-" & $key
        $key = $table[$a] & $key
    Next
    Return $key
EndFunc   ;==>GetWXPCDKey

edit: fixed a typo.

Edited by eltorro
Link to comment
Share on other sites

Here is a function I translated from a vbs script I found somewhere. It was likely translated from Magic Jelly Bean Keyfinder.

It allows one to recover the CD key from the windows registry for reinstall, license auditing, etc.

I have only tested it with WinXP 32-bit SP3.

It will likely work with 2k on, but not sure.

I also suspect the same algorithm will work with office and other M$ products.

Code Removed

Hope you find it useful.

I also made an u3 version but it's a bit different because it only get's local keys and then it display's it with MsgBox

So.

Posted Image

Download U3: WCK_U3.ZIP

Edited by jeantje
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...