VBScript > AHK-code translation needed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
moefr01
Posts: 115
Joined: 25 Nov 2015, 09:01
Location: Germany

VBScript > AHK-code translation needed

05 Nov 2017, 13:10

I'd like to store my active Windows product key for further backup-solution, but couldn't convert the product key out of registry with AHK purely, so I created a VBScript embedded within my AHK-script below.
>> works fine for Windows 7, 8.x and 10 <<
Unfortunately VBScript is not my favourite scripting language :crazy: , 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
moefr01 :wave:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 215 guests