Jump to content

Why do I get a wrong key?


cherdeg
 Share

Recommended Posts

Hi!

Yesterday I've made up this code (with help of an example from here):

Local $b_BinaryKey  = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")
Local $s_ProductKey = _DecodeProductKey($b_BinaryKey)
$i_ButtonCliecked   = MsgBox(36, "Change Windows Product Key", "Your current" & @OSVERSION & " product key is: " & @CRLF & @CRLF & $s_ProductKey & @CRLF & @CRLF & "Do you really want to change it?")

If $i_ButtonCliecked = 6 Then

    Dim $s_VOL_PROD_KEY = InputBox("New Volume License Key", "Please enter the new key for this installation: ")
    If @error Then Exit
    $s_VOL_PROD_KEY     = StringReplace($s_VOL_PROD_KEY, "-", "")

    $o_WMIservice       = ObjGet("winmgmts:{impersonationLevel=impersonate}")
    $o_WPAinstances     = $o_WMIservice.InstancesOf("win32_WindowsProductActivation")

    for $o_Item in $o_WPAinstances
        $s_result = $o_Item.SetProductKey($s_VOL_PROD_KEY)
        If $s_result = 0 Then
            MsgBox(64, "SUCCESS", "The product key was changed.")
        Else
            MsgBox(16, "ERROR", "An error has happened, check it product key was changed.")
        EndIf
    Next

EndIf


Func _DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result

    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789","")

    $binaryDPID = stringmid($binaryDPID,105,30)

    For $i = 1 to 29 step 2
        $bKey[int($i / 2)] = dec(stringmid($binaryDPID,$i,2))
    next

    For $i = $dlen -1 To 0 Step -1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen -1 To 0 Step -1
                $Value = Bitor(bitshift($hi ,- 8) , $bKey[$n])
                $bKey[$n] = int($Value / 24)
                $hi = mod($Value , 24)
            Next
            $sKey[$i] = $Digits[$hi +1]
        EndIf

    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next

    Return $Result
EndFunc

My Problem: The script does not produce the correct product key. Did Microsoft change something in the encryption of the product keys with SP3? Please help.

Best Regards,

Chris

Edited by cherdeg
Link to comment
Share on other sites

It's been discussed about before, search for it.

Thanks for the kind hint - but due to the fact that the search function is still not working as proposed, I couldn't find anything. What about you telling me the needed info in a few words?

EDIT: Just keep it, thanks.

If @extended==3 Then $b_BinaryKey = Hex($b_BinaryKey)
Edited by cherdeg
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...