- Reads the Registry Digital Product Id and converts to readable format
Tested on Windows 8 and 10 or above, not sure about other versions, do mention in comments if it works for you.
Tested on Windows 8 and 10 or above, not sure about other versions, do mention in comments if it works for you.
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 |