This VBScript retrieves the ProductID
from the registry and converts it to the Product Key
that you entered or one that came pre-installed. Now, you may be wondering, why you would need a script such as this in the first place. Well, what if you need to reactivate Windows or reinstall Windows on your computer and you don’t have the key handy. The product key is store in the registry but it is stored in binary format so we have to do a little conversion to make it readable.
All you need to do is, copy and paste the following script into Notepad and save the file with any name but the extension should be .vbs (e.g. winkey.vbs). Then just double-click the file to get your product key.
Set WshShell = CreateObject("WScript.Shell")
MsgBox "Windows Product Key" & vbnewline & vbnewline & _
ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(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
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i - 1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function
Code language: VBScript (vbscript)