A quick article with the code to retrieve your product key in Windows 7 with a small VB script file. There are other articles on the web about this but the ones I found returned errors such as WshShell not valid. This article has a working example applicable to Windows 7 Professional.
Why?
With the Windows 10 operating system offered as a free upgrade (for Windows 7 or later at time of print), I needed the serial number / product key from my Windows 7 Professional 32-bit operating system. I didn't want to dig through my CD/DVDs to find my original windows 7 disc and no longer have access to the email account when I purchased Windows 7 (my university one).
How?
I'm going to use my trusty notepad program, copy the following code to it, and run it:
- Create a notepad file called read_product_id.vbs
- Copy the following code to the file:
copyraw
Set wshShell = CreateObject("Wscript.Shell") MsgBox 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
- Set wshShell = CreateObject("Wscript.Shell")
- MsgBox 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
- Save the file and double-click on it to run it
- Done