>> works fine for Windows 7, 8.x and 10 <<
Unfortunately VBScript is not my favourite scripting language , so it would be great if someone genius would be soooo kind translating the VBScript into native AHK-Code.
Code: Select all
; Embedded VBScript to get the Windows(R) 7/8.x/10 DigitalProductID (registry) converting to Product Key
myVBScript =
(
Set WshShell = WScript.CreateObject("WScript.Shell")
RegKeyPath = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
ProductKey = ConvertKey(WshShell.RegRead(RegKeyPath))
MsgBox ProductKey, , "My Windows Product-Key:"
Function ConvertKey(KeyInput)
Const KeyOffset = 52
Dim isW8, i, x, Cur, KeyOutput, Last, keypart1, insert
'If Windows >= 8:
isW8 = (KeyInput(66) \ 6) And 1
KeyInput(66) = (KeyInput(66) And &HF7) Or ((isW8 And 2) * 4)
i = 24
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = KeyInput(x + KeyOffset) + Cur
KeyInput(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
Last = Cur
Loop While i >= 0
keypart1 = Mid(KeyOutput, 2, Last)
insert = "N"
KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
If Last = 0 Then KeyOutput = insert & KeyOutput
ConvertKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
End Function
)
FileAppend, %myVBScript%, ProductKey.vbs
RunWait, ProductKey.vbs
FileDelete, ProductKey.vbs
ExitApp