Subscribe

Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts

Search

Archives

Get your Windows product key from a script

Post image for Get your Windows product key from a script

by Steve Wiseman on August 15, 2012 · 35 comments

in Tips,Utility


.

A while back Stacy asked:

“Hi Steve. I was wondering if you knew of a way to get a windows product key from a script. I need it because we are trying to audit our windows licensing, and see if we have any duplicate keys”

And by coincidence, I got this email from Matthew P:

“Do you guys have a quick tool to see what model a computer is?

Just as soon as I typed this I remembered I already have a tool for this sort of thing, and I’m attaching it now…”

The real gem in Matthew’s script is the ability to pull out a Windows product key.

This info is located in the registry under

HKLM\Software\Microsoft\Windows NT\CurrentVersion

It is the value named: DigitalProductId

If you look at it, you will realize it is encrypted:

Product ID Encrypted

That is what his script takes care of. It reverses the simple XOR encryption and turns that numeric mess into a readable product key.

Not a real product key

You can get the script from here:

GetProductKey.dat

Just rename to .vbs, and it outputs the OS version, and key to the console.

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 35 comments… read them below or add one }

1 Mike Dunkirk August 15, 2012 at 2:29 pm

Fantastic tip steve. The thing even works on my old 2000 box!

2 Jennifer August 15, 2012 at 2:37 pm

Hi Steve. Thanks for this script. Soo glad I don’t have to mess with magic jelly bean after they ruined it with adverts

3 Steve Wiseman August 15, 2012 at 2:38 pm

Yea…Magic Jelly Bean key finder was great. It is just a load of spyware now. Too bad. We will have to find a way of pulling office keys too…since MJB did a great job of that.

4 Ron August 15, 2012 at 8:08 pm

Steve, Thanks for the tips..
are you going to make us enter a name and email address EVERYTIME we go to DL one of your scripts? Just curious, because I do that so much in a day already…. sorry, just one of my peeves 😛

5 Mark August 17, 2012 at 10:23 am

This script seems to give me trouble on x64 version of Windows. Any fix for that? 🙂

6 Steve Wiseman August 17, 2012 at 10:25 am

Hi Ron,

Sorry about that. We had to do something…the autobot scrapers were killing our bandwidth. Putting it behind the email prevents this. I think we can change it so within the first 48~72 hours (of the blog posting) you don’t need to get it via email. That would solve both problems 😉

7 Steve Wiseman August 17, 2012 at 10:26 am

Hi Mark,

This is an issue. A few have reported this. The issue is with Windows Vista/7 x64 Registry reflection. I think a way for us to fix this is to move it into an EXE so we have more control on how it accesses the registry. Keep an eye out here for a new version.

8 Alain September 5, 2012 at 1:50 pm

Another free, open source tool called “Enchanted Keyfinder”.
More information about it can be found here:

http://ekeyfinder.sourceforge.net/index.php?lang=en&page=about

9 Juan November 16, 2012 at 3:43 am

Hi Steve,

Thanks for the cool stuff.

10 Jason November 28, 2012 at 11:15 am

Just a question, does this script work on all versions of windows? I am having issues when running it on Windows 2008 64bit.

Microsoft Windows Server 2008 R2 Standard (6.1.7601), BBBBB-BBBBB-BBBBB-BBBBB-BBBBB

Just wondering if this is expected or not…
Thanks.

11 Steve Wiseman November 28, 2012 at 4:16 pm

It has trouble with 64 bit windows…since it windows has a feature called registry redirection.

I think if you call the script from a 64 bit version of cscript.exe then it will give you the serial.

This can be done by directly calling the cscript.exe that is 64 bit under c:\windows\system32

12 Raghav Singh March 29, 2013 at 9:11 am

How can i get my remote systems os key through above suggested vb script.
Please help on this i need to capture 2000 PC key for audit purpose.

13 Avinash Sharma April 15, 2013 at 5:46 am

For Windows 2008 R2 64bit,

Just Change the “DigitalProductId” to “DigitalProductId4” and it will work.

Steve, please correct me if I am wrong as I saw “DigitalProductId4” under the same path and was able to get the keys instead of BBBBB-BBBBB-BBBBB-BBBBB-BBBBB

Thanks,
Avinash

14 Steve Wiseman April 17, 2013 at 9:04 am

Hello Avinash,

Thanks for the tip. I was not aware this would fix the issue.

Thanks,

Steve

15 Chris April 22, 2013 at 7:50 am

I tried Avinash Sharma’s suggestion to change the “digitalproductid” to digitalproductid4″ it worked but i tried this .vbs on different 2008 64bit servers and all showed the same product key, while i am sure these servers have differnts product keys. any suggestions Steve???

16 Steve Wiseman April 22, 2013 at 11:57 am

I believe that you need to run it from the 64 bit version of cscript.exe

You can do it by calling it like this:

c:\windows\system32\cscript.exe getproductkey.vbs

17 Chris April 23, 2013 at 4:32 am

i did what you suggested. same results…

18 Alan April 26, 2013 at 4:55 am

I am running into the same problem as Chris, using this script on a x64 with a without the “DigitalProductId4” change and with and without the “c:\windows\system32\cscript.exe” seems to provide the wrong key.

Does anyone else have any suggestions?

19 Steve Wiseman April 26, 2013 at 9:53 am

Hi Everyone,

This is really a tough one to get around. What is happening is Windows is automatically redirecting the registry requests to the 32 bit hive on 64 bit windows. In VBScript there is no way to tell it not to do this.

The only thing I can suggest in this situation now is to try and use the Get-Product-Key powershell script from MS:

http://gallery.technet.microsoft.com/scriptcenter/Get-product-keys-of-local-83b4ce97

20 Ivan May 21, 2013 at 9:05 am

Works for me. Thanks.

21 Ken June 1, 2013 at 5:37 pm

Steve,
This is off the subject but I’m in need of help with an issue that you seem uniquely qualified to perhaps offer. Do you know of a command, method or tool of any kind to log into the security console while reinstalling an operating system (in my case Windows XP Pro 2002) from a recovery disk? I need to change the administrator password and have forgotten the admin password so can’t log in to finish the installation. Pressing SHIFT + F10 when utilities are loading gets me to the cmd.exe console but entering NUSRMGR.CPL at the prompt is no longer getting me in to make the changes. Is this covered in any of your news letters currently or archived? Any help will be greatly appreciated.
Thanks for any advice you can give…

22 srinivasa June 3, 2013 at 3:51 am

Steve,

Thanks it worked but how do we get other MS related product keys in the same machine

23 Mark August 1, 2013 at 1:59 pm

Steve

I just stumbled upon your site, while looking for a routine to delete empty folders – then found this post.

I highly suggest you check out ANYTHING from nirsoft.net.

Like many of the utilities you release, Nir Sofer releases crazy good stuff.

Specifically check out ProduKey at http://www.nirsoft.net/utils/product_cd_key_viewer.html

Mark

24 Randy August 23, 2013 at 1:53 am

Hey Ken, Did you ever get that computer unlocked? I found a tool that you download on another computer and burn to a disk. Put the disk into the locked computer and boot to it. Answer with the (default) to all the prompts, and it will remove the password. remove the disk, reboot, and if asked for a password, just hit enter, and you’ll boot right up. A lot of people could probably use that tool, but I don’t remember the name. Just search for “admin password remover” or something. GL

25 Emiel Wieldraaijer September 8, 2013 at 4:33 am

Serial retrieved for Windows 8 is not correct

26 Steve Wiseman September 8, 2013 at 12:19 pm

Hi Emiel,

I think you are running the 64 bit version of Windows 8. In that case, you need to run the 64 bit version of cscript.exe to make it work.

You can find it under:

%systemroot%\sys­native\cscript.exe

Just a guess…I have not tested this yet.

Thanks,

Steve

27 Emiel Wieldraaijer September 9, 2013 at 5:53 pm

no.. it does not retrieve the right serial.. check nirsoft produkey.exe ..
i retrieves the right serial .. i tested this script on 4 computers..

28 Steve Wiseman September 11, 2013 at 9:52 am

You are right productkey.exe works great. Unfortunately sometimes you want it in a script.

I will need to see why the key is not getting pulled from VBScript. I am pretty sure it is a registry redirection issue. This is a known issue with VB Script.

29 Charlie Snow October 25, 2013 at 4:38 pm

I am trying to find a Mac equivalent (either script or program) to pull Product Keys. Unfortunately, when a refresh is done on a Mac (quite frequently around here, and the person that placed the machine in service didn’t file the key in the systems folder… There is no way to pull it from the computer. Specifically for MS Office Products.

Anyone know of a way?

TIA,
Charlie

30 Mike December 19, 2013 at 2:45 pm

Thanks, this worked on my 2008 R2 Standard by changed the the “DigitalProductId” to “DigitalProductId4″

31 Mike December 19, 2013 at 2:56 pm

Now after looking at all my servers its seems to be simply giving the same 2 numbers every other time I test a different server.

Does not work.

32 crashdude July 22, 2014 at 4:59 am

Thanks man! Works wonders!

33 nothingthere October 3, 2014 at 11:48 am

there is no file to download.

34 Juan Gaudnzi November 6, 2014 at 11:06 am

Hi !
It works in Windows 7 (x64 and x86) without a problem.
But I have a little problem, I downloaded for using in Windows Server. Is there any similar file to perform the same action ?
Thanks !

35 Steve Wiseman November 7, 2014 at 10:28 am

Hello Juan,

I now recommend this utility over the script:

http://www.nirsoft.net/utils/product_cd_key_viewer.html

It can work on any version of windows.

Leave a Comment

Category Links - Windows Forum - Exchange Forum