XP-CD Key auslesen

  • Hallo, ich arbeite an einem Inventarisierungsscript. Dazu wollte ich auch die CD-Keys von Win XP auslesen.

    Im englischen Forum gibts auch ein Script dazu, es liest den Key aber leider falsch aus:

    Spoiler anzeigen
    [autoit]

    Dim $Bin
    $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")

    [/autoit] [autoit][/autoit] [autoit]

    InputBox("Product Key", "Your " & @OSVERSION & " product key is:", DecodeProductKey($bin), "", -1, 100, -1, -1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Return $Result
    EndFunc

    [/autoit]

    Dazu hab ich ein Code Beispiel in VB gefunden, schaff es aber nicht ganz, das zu übersetzen
    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=57164

    Auf Externe Programme möchte ich nicht zurückgreifen.

    Einmal editiert, zuletzt von Bitboy (8. Dezember 2009 um 13:17)

  • Hi,

    kann es sein, dass Du eine OEM Version benutzt?

    Wenn ja, ist im englischen Forum ein Verweis:

    Zitat


    There is however the potential for failure if you are using an OEM version because of the way that OEM product keys work. The Product Key in the registry may not be the same as the Product Key on your sticker in OEM versions.

    ;-))
    Stefan

  • Nee, hatte externe Programme zum Vergleich benutzt, darunter auch Everest, die haben alle denselben angezeigt.

    Hab auch den Fehler im englischen Forum gefunden, ein Befehl hat gefehlt.

    Hab es jetzt mal entsprechend umgebaut:
    (Kein Plan ob es unter anderen Windowsversionen funktioniert, wäre schön wenn es mal jemand testen könnte)

    Spoiler anzeigen
    [autoit]

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

    $binaryDPID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")
    If @extended = 3 Then $binaryDPID = Hex($binaryDPID)

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 28 To 0 Step -1
    If Mod(($i + 1), 6) = 0 Then
    $sKey[$i] = "-"
    Else
    $hi = 0
    For $n = 14 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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Return $Result
    EndFunc

    [/autoit]
  • Dann hast du eine x64-Version.
    Wenn du ein x86-Programm ausführst greift dieses in der Registry nicht mehr auf "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft..." zu sondern auf "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft...".
    Das ist dann natürlich falsch weil dort kein Key steht.

    Lösung also: als x64 kompilieren - dann stimmen auch die Registry-Pfade wieder

  • Bei mir is es wurscht ob das extended mit beachtet wird oder nicht.
    Sobald das als x86 kompiliert ist funzt da nichts.

    Also wiederhole ich gerne noch einmal:
    Hast du ein x64-BS so musst du das Skript auch als x64 kompilieren damit er den Key korrekt ausliest.

  • Hab aber kein x64 System...

    Naja da es anscheinend auch auf anderen Windows-Versionen läuft hab ich die Funktion nochmal umbenannt und korrigiert. Jetzt läuft es (bei mir) in beiden Fällen.

    Spoiler anzeigen
    [autoit]

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

    $binaryDPID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")
    $Test = @extended

    [/autoit] [autoit][/autoit] [autoit]

    If Not @Compiled Then
    If $Test = 3 Then $binaryDPID = Hex($binaryDPID)
    EndIf

    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789","")
    $binaryDPID = stringmid($binaryDPID,105,30)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 28 To 0 Step -1
    If Mod(($i + 1), 6) = 0 Then
    $sKey[$i] = "-"
    Else
    $hi = 0
    For $n = 14 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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Return $Result
    EndFunc

    [/autoit]

    Falls noch jemandem was zu dem @extended einfällt darf gern gepostet werden. Auch ein Test ob es unter Vista funktioniert wäre nett, ansonsten setz ich das Topic mal als gelöst.

    Danke an alle für die Hilfe

  • Hi,
    dein Skript funktioniert unter Win7 x64 nicht, wenn es als x86-Skript ausgeführt wird.
    Wenn du aber bei RegRead HKLM64 anstatt HKEY_LOCAL_MACHINE angibst, dann funktioniert bei mir das Skript unter Win7 x64 sowie unter XP als x86-Skript

    [autoit]

    $binaryDPID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")
    ;gegen
    $binaryDPID = RegRead("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductID")

    [/autoit]

    MFG. RAPTOR-ONE

  • Hallo !

    Ist zwar schon gelöst aber der fehler liegt am auslesen!

    [autoit]

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

    [/autoit]


    Richtig wehr ab der 107 stelle!

    [autoit]

    $binaryDPID = stringmid($binaryDPID,107)

    [/autoit]


    Beim reg auslesen wird 0x vorne rangestellt also zwei stellen zu früh wird der code gerechnet!

    Den code habe ich ihr im forum gefunden der es von Xenobiologist - 2006

    Von mir geendert:

    Spoiler anzeigen
    [autoit]

    Dim $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID")
    MsgBox(0, '', 'Dein Produkt Key: ' & ProKey($Bin))
    Func ProKey($bia)
    Dim $a[15], $b[29], $c[24], $s = 15, $d = 29, $v = 0, $n = 0, $i = 0, $r, $h = 0
    $c = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $bia = StringMid($bia, 107, 30)
    For $i = 1 To 29 Step 2
    $a[Int($i / 2)] = Dec(StringMid($bia, $i, 2))
    Next
    For $i = $d - 1 To 0 Step -1
    If Mod(($i + 1), 6) = 0 Then
    $b[$i] = "-"
    Else
    $h = 0
    For $n = $s - 1 To 0 Step -1
    $v = BitOR(BitShift($h, -8), $a[$n])
    $a[$n] = Int($v / 24)
    $h = Mod($v, 24)
    Next
    $b[$i] = $c[$h + 1]
    EndIf
    Next
    For $i = 0 To 28
    $r = $r & $b[$i]
    Next
    Return $r
    EndFunc ;==>ProKey

    [/autoit]

    LG Kleiner

    2 Mal editiert, zuletzt von kleiner27 (8. Dezember 2009 um 19:58)

  • Hier der Versuch den Key auch von x64 Systemen zu lesen. Da das ganze über WMI läuft, können auch Remote System abgefragt werden.

    Da ich momentan Zuhause bin, kann ich den Remote Check nicht durchführen!

    Für einen Test von einem x32 auf einen x64 System wäre ich dankbar!

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_UseUpx=n
    ;~ #AutoIt3Wrapper_Change2CUI=y

    [/autoit] [autoit][/autoit] [autoit]

    If $CmdLine[0] > 0 Then
    MsgBox(0, "Windows OS Product Key", DecodeProductKey($CmdLine[1]))
    Else
    MsgBox(0, "Windows OS Product Key", DecodeProductKey("localhost"))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Func DecodeProductKey($srv)
    Local $objWMILocator, $objRegService, $BaseKey, $BaseKey64, $oReg, $Product_Key, $Key, $arrSubKeys, $i, $t, $p
    Dim $BinaryDPID, $TempBinaryDPID
    $BaseKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
    $BaseKey64 = "SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\"
    $strValueName = "DigitalProductId"
    Const $HKLM = 0x80000002

    [/autoit] [autoit][/autoit] [autoit]

    $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $srv & "\root\default:StdRegProv")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If IsObj($oReg) Then
    If @OSArch = "X64" And ($srv = @ComputerName Or _ ;local check
    $srv = "localhost" Or _
    $srv = @IPAddress1 Or _
    $srv = @IPAddress2 Or _
    $srv = @IPAddress3 Or _
    $srv = @IPAddress4) Then
    $BinaryDPID = StringMid(RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey, $strValueName), 3) ;if exe is x64
    If $BinaryDPID = "" Then $BinaryDPID = StringMid(RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey, $strValueName), 3) ;otherwise exe is x32
    Else
    $oReg.GetBinaryValue($HKLM, $BaseKey, "DigitalProductId", $Product_Key) ;remote check
    If Not IsArray($Product_Key) Then
    $oReg.GetBinaryValue($HKLM, $BaseKey64, "DigitalProductId", $Product_Key)
    EndIf
    $BinaryDPID = ""
    For $i = 0 To UBound($Product_Key) - 1
    $BinaryDPID &= Hex($Product_Key[$i], 2)
    Next
    EndIf
    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 $ProductKey
    $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
    $ProductKey = $ProductKey & $sKey[$i]
    Next
    SetError(0)
    Return $ProductKey
    Else
    SetError(1)
    MsgBox(16, "ERROR", "An error has occured!", 10)
    EndIf
    EndFunc ;==>DecodeProductKey

    [/autoit]

    Danke,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    2 Mal editiert, zuletzt von UEZ (9. Dezember 2009 um 10:12)

  • Also ich compile es, und rufe dann in der cmd "Winkey.exe 192.168.178.69" auf?

    Spoiler anzeigen

    Wenn ich es uncompiled lasse, und MsgBox(0,"",DecodeProductKey("192.168.178.69")) verwende, gibt Scite die folgende Fehlermeldung

    Spoiler anzeigen

    C:\Users\Shkal\Desktop\AutoIt\12.09\WinKey.au3 (16) : ==> The requested action with this object has failed.:
    $objRegService = $objWMILocator.ConnectServer($srv, "\root\default", "", "", "", "", 0x80)
    $objRegService = $objWMILocator.ConnectServer($srv, "\root\default", "", "", "", "", 0x80)^ ERROR
    ->00:45:05 AutoIT3.exe ended.rc:1
    +>00:45:06 AutoIt3Wrapper Finished
    >Exit code: 1 Time: 2.968

    Getestet wurde von Vista x86 -> Vista x64 im LAN.
    Hoffe das hilft dir weiter