Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
VBS Script to get the Windows(R) 7 Product Key from a PC's registry.
' VBS Script to get the Windows(R) 7 Product Key from a PC's registry.
'
' Save the VBScript as "getWin7Key.vbs" somewhere on your Windows7 PC.
' Now, when you double-click the local script file an alertbox pops up
' displaying the product key stored in the machine's Windows registry.
Set WshShell = WScript.CreateObject("WScript.Shell")
KeyPath = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
MsgBox ExtractKey(WshShell.RegRead(KeyPath))
Function ExtractKey(KeyInput)
Const KeyOffset = 52
i = 28
CharWhitelist = "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(CharWhitelist, 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
ExtractKey = KeyOutput
End Function

Thank you so much! This is much better than using downloaded applications, which gave me concern that my Key would be pirated.

k00sa commented Jan 22, 2016

Can u explain me how to modify source code to load registry from custom folder. Fox example i exported registry to my C:\user\desktop...
and can i somehow load in that way ? (: or just put hex string from registry to .txt and then read ? (:

Hi,
Thanks for the great code. How do you change it to save/add the output to a text file? I want to run this on my domain computers.
Many thanks,
Sina

Here is another way to find Windows product key: http://www.uukeys.com/find-windows-7-product-key.html

@ghost

ghost commented Dec 30, 2016

To display key in console run cscript.exe get-win7-productkey.vbs
to save it to file: cscript.exe get-win7-productkey.vbs > key.txt

Perfect!

You can also just click on the MsgBox popup and press CTRL+C and paste the output into a text file.

cononda commented Jan 23, 2017

To dawjan
display key in console run cscript.exe get-win7-productkey.vbs
to save it to file: cscript.exe get-win7-productkey.vbs > key.txt

Thanks for this but I get the textfile as follow:
Microsoft (R) Windwos Script Host, Version 5.8
Copyright (R) Microsoft Corporation 1996-2001. Alle Rechte Vorbehalten.

No key written in the file. Any recommendations?

PS running the script only I get the Product Key displayed in a Popupwindows...

tRekiP commented Mar 3, 2017

Where i have to write it? Im newbie in these registry and others.. Start -> Registy (some file) -> copy that command -> past here?

For friends who wanna windows 7 product key,visit this page: www.vip4sale.com Fast delivery, and the keys are genuine!

Check here: http://www.microsoftonlinekey.com , you will find many CHEAP Microsoft keys.

Never mind , the Windows Password recovery tool may be a effective software for us to solve this problem ,
Here is a tutorial that you can get more steps about how to recover Windows Password :https://www.recoverywindowspassword.com/reset-windows-7-login-password-in-3-ways.html

Go site http://www.vanskeys.com to get genuine windows key here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment