Skip to content

Instantly share code, notes, and snippets.

@pishangujeniya
Last active March 1, 2020 08:40
Show Gist options
  • Save pishangujeniya/98b3826de8aa8567e964e8ab9bf961f6 to your computer and use it in GitHub Desktop.
Save pishangujeniya/98b3826de8aa8567e964e8ab9bf961f6 to your computer and use it in GitHub Desktop.
Get Windows installed product key from registry in plain readable format
Set WshShell = CreateObject("WScript.Shell")
readableKey = ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
MsgBox(readableKey)
Function ConvertToKey(Key)
insert = ""
AKey = ""
BKey = ""
CKey = ""
DKey = ""
EKey = ""
Const KeyOffset = 52
isWin8 = (Key(66) \ 6) And 1
Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
i = 24
Chars = "BCDFGHJKMPQRTVWXY2346789"
last = 0
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24)
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
If (isWin8 = 1) Then
keypart1 = Mid(KeyOutput, 2, Last)
insert = "N"
KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
If Last = 0 Then KeyOutput = insert & KeyOutput
End If
AKey = Mid(KeyOutput, 1, 5)
BKey = Mid(KeyOutput, 6, 5)
CKey = Mid(KeyOutput, 11, 5)
DKey = Mid(KeyOutput, 16, 5)
EKey = Mid(KeyOutput, 21, 5)
ConvertToKey = AKey & "-" & BKey & "-" & CKey & "-" & DKey & "-" & EKey
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment