Post by just me » 07 Nov 2017, 03:33
Moin,
ich habe hier etwas, das auf meinem Rechner einen Key ausgibt, der mit dem des VB-Skripts identisch ist. Um erst einmal möglichst nahe am VB-Skript zu bleiben, habe ich dabei den Hex-String aus
RegRead in ein 0-basiertes Array übertragen. Der 'ominöse' Code ist noch drin, ich habe aber nach wie vor Zweifel am Sinn von
| ((IsW8 & 2) * 4), zumindest in AHK. Das Arrayelement 66 wird hier auf
1 gesetzt, weil das Element den Wert
9 enthält (9 & 0xF7 = 1). Du kannst ja probieren, ob Dein Workaround
Key[66] := 1 zuverlässig funktioniert:
Code: Select all
#NoEnv
MsgBox, % GetWinProductKey()
ExitApp
GetWinProductKey() {
Static Chars := "BCDFGHJKMPQRTVWXY2346789"
Static Insert := "N"
Static KeyOffset := 52
ProductKeyArray := []
RegRead, ProductKey, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, DigitalProductId
Loop, % (StrLen(ProductKey) // 2) {
I := A_Index - 1
ProductKeyArray[I] := "0x" . SubStr(ProductKey, (I * 2) + 1, 2)
}
IsW8 := (ProductKeyArray[66] // 6) & 1
ProductKeyArray[66] := (ProductKeyArray[66] & 0xF7) | ((IsW8 & 2) * 4)
I := 24
KeyOutput := ""
While (I >= 0) {
Cur = 0
X := 14
While (X >= 0) {
Cur := Cur * 256
Cur := ProductKeyArray[X + KeyOffset] + Cur
ProductKeyArray[X + KeyOffset] := (Cur // 24) & 0xFF
Cur := Mod(Cur, 24)
X--
}
KeyOutput := Substr(Chars, Cur + 1, 1) . KeyOutput
Last := Cur
I--
}
KeyPart1 := SubStr(KeyOutput, 2, Last)
KeyOutput := StrReplace(SubStr(KeyOutput, 2), KeyPart1, KeyPart1 . Insert, , 1)
If (Last = 0)
KeyOutput := Insert . KeyOutput
Return SubStr(KeyOutput, 1, 5) . "-" . SubStr(KeyOutput, 6, 5) . "-" . SubStr(KeyOutput, 11, 5) . "-"
. SubStr(KeyOutput, 16, 5) . "-" . SubStr(KeyOutput, 21, 5)
}
Hast Du noch den Link für das VB-Skript?
Moin,
ich habe hier etwas, das auf meinem Rechner einen Key ausgibt, der mit dem des VB-Skripts identisch ist. Um erst einmal möglichst nahe am VB-Skript zu bleiben, habe ich dabei den Hex-String aus [c]RegRead[/c] in ein 0-basiertes Array übertragen. Der 'ominöse' Code ist noch drin, ich habe aber nach wie vor Zweifel am Sinn von [c]| ((IsW8 & 2) * 4)[/c], zumindest in AHK. Das Arrayelement 66 wird hier auf [c]1[/c] gesetzt, weil das Element den Wert [c]9[/c] enthält (9 & 0xF7 = 1). Du kannst ja probieren, ob Dein Workaround [c]Key[66] := 1[/c] zuverlässig funktioniert:
[code]#NoEnv
MsgBox, % GetWinProductKey()
ExitApp
GetWinProductKey() {
Static Chars := "BCDFGHJKMPQRTVWXY2346789"
Static Insert := "N"
Static KeyOffset := 52
ProductKeyArray := []
RegRead, ProductKey, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, DigitalProductId
Loop, % (StrLen(ProductKey) // 2) {
I := A_Index - 1
ProductKeyArray[I] := "0x" . SubStr(ProductKey, (I * 2) + 1, 2)
}
IsW8 := (ProductKeyArray[66] // 6) & 1
ProductKeyArray[66] := (ProductKeyArray[66] & 0xF7) | ((IsW8 & 2) * 4)
I := 24
KeyOutput := ""
While (I >= 0) {
Cur = 0
X := 14
While (X >= 0) {
Cur := Cur * 256
Cur := ProductKeyArray[X + KeyOffset] + Cur
ProductKeyArray[X + KeyOffset] := (Cur // 24) & 0xFF
Cur := Mod(Cur, 24)
X--
}
KeyOutput := Substr(Chars, Cur + 1, 1) . KeyOutput
Last := Cur
I--
}
KeyPart1 := SubStr(KeyOutput, 2, Last)
KeyOutput := StrReplace(SubStr(KeyOutput, 2), KeyPart1, KeyPart1 . Insert, , 1)
If (Last = 0)
KeyOutput := Insert . KeyOutput
Return SubStr(KeyOutput, 1, 5) . "-" . SubStr(KeyOutput, 6, 5) . "-" . SubStr(KeyOutput, 11, 5) . "-"
. SubStr(KeyOutput, 16, 5) . "-" . SubStr(KeyOutput, 21, 5)
}[/code]
Hast Du noch den Link für das VB-Skript?