Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Created August 16, 2014 15:52
Show Gist options
  • Save eyecatchup/d577a2628666a0ad1375 to your computer and use it in GitHub Desktop.
Save eyecatchup/d577a2628666a0ad1375 to your computer and use it in GitHub Desktop.
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
@sunsprite
Copy link

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

@k00sa
Copy link

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 ? (:

@SinaAnderson
Copy link

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

@ffansszi
Copy link

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

Copy link

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

@ctooth16
Copy link

Perfect!

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

@cononda
Copy link

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
Copy link

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?

@windowskeys
Copy link

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

@windowskeys
Copy link

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

@Manskerty
Copy link

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

@CristinaHopkins
Copy link

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

@private2020
Copy link

' 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

Set FSO = CreateObject("Scripting.FileSystemObject")

' How To Write To A File
Set File = FSO.CreateTextFile("Productkey.txt",True)
File.Write ExtractKey
File.Close

End Function

use this to copy the key in text file

@Teqnkka
Copy link

Teqnkka commented Aug 31, 2020

Just save the text in the notepad, Save as -> [...].vbs then double click it from the location it was saved.

@szalony9szymek
Copy link

very good better then the garbage software filled with viruses

@chandrasekharsah
Copy link

Thanks a lot. It's much better than using downloaded apps.

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