Jump to content
Sign in to follow this  
blakel

Windows CD Key

Recommended Posts

blakel

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.

Share this post


Link to post
Share on other sites
eltorro

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

Share this post


Link to post
Share on other sites
blakel

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

Not at all, that is what this place of the forum is for.

Good improvements.

Share this post


Link to post
Share on other sites
lsakizada

See this URL with similar functionality for office:)

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
jeantje

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

Share this post


Link to post
Share on other sites
KenNichols

Thanks! I used

CODE
$pc = @ComputerName

MsgBox(0,"Windows Key",GetWXPProductName($pc) & " " & @OSServicePack & @CRLF & "CDKey: " & GetWXPCDKey($pc))


[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!

Share this post


Link to post
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
Sign in to follow this  

×