contain windows serial key

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

contain windows serial key

#1 Post by Adrianvdh » 10 Jun 2013 06:06

hello everyone

Could you tell me how I can contain my serial key in a batch file and store it in a varible. i.e. "SerialKey"

Thanks for your time :)

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: contain windows serial key

#2 Post by Squashman » 10 Jun 2013 06:58

set SerialKey=1323282523234

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: contain windows serial key

#3 Post by foxidrive » 10 Jun 2013 07:18

*grins at squashman*

I wonder what purpose one would have for wanting a serial key in a variable for?
There are several programs that will show you your Windows key.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: contain windows serial key

#4 Post by aGerman » 10 Jun 2013 10:43

Found a small code snippet in my collection. Not quite certain if it really works though.

Code: Select all

@echo off &setlocal
call :GetProductKey sWinProdKey
echo Windows Product Key: %sWinProdKey%
echo(
pause
goto :eof

:GetProductKey outVarName
setlocal EnableDelayedExpansion
set "sKeyChar=BCDFGHJKMPQRTVWXY2346789"
set "sRegKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
set "sRegVal=DigitalProductId"

for /f "tokens=3" %%i in ('reg query "%sRegKey%" /v "%sRegVal%"') do set "sHex=%%i"

set /a "n = 52"
for /l %%i in (104,2,132) do set /a "aRegValue_!n! = 0x!sHex:~%%i,2! , n += 1"

for /l %%b in (24,-1,0) do (
  set /a "c = 0 , n = %%b %% 5"
  for /l %%i in (66,-1,52) do set /a "c = (c << 8) + !aRegValue_%%i! , aRegValue_%%i = c / 24 , c %%= 24"
  for %%j in (!c!) do set "sProductKey=!sKeyChar:~%%j,1!!sProductKey!"
  if %%b neq 0 if !n!==0 set "sProductKey=-!sProductKey!"
)
endlocal &set "%~1=%sProductKey%" &goto :eof

Regards
aGerman

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: contain windows serial key

#5 Post by Squashman » 10 Jun 2013 10:49

Works on Windows 7 64bit.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: contain windows serial key

#6 Post by aGerman » 10 Jun 2013 10:57

Yeah, I also get a key back (Win7 x86) but I can't verify it. What did you use for cross-checking?

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: contain windows serial key

#7 Post by Aacini » 10 Jun 2013 11:16

Tested on Win XP SP3 and got this:

Code: Select all

Windows Product Key: TKYG4-[snip]-TRD6M

But the real key is entirely different. Just the "Y in first group and the "D" in last one matches...

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: contain windows serial key

#8 Post by aGerman » 10 Jun 2013 11:48

OK you aroused my curiosity. I installed "Belarc Advisor" and it found the same key as my batch snippet did. Stalemate :lol:

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: contain windows serial key

#9 Post by Squashman » 10 Jun 2013 12:20

Verified with Product Key Finder.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: contain windows serial key

#10 Post by foxidrive » 10 Jun 2013 17:16

The key it reports on Windows 8 is not the same as Belarc Advisor, and neither of them match the key from my records.

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: contain windows serial key

#11 Post by Aacini » 10 Jun 2013 17:20

I am somewhat confused with this topic... :?

My Win XP computer is a laptop older than 6 years old that have a plastic label in the bottom with an hologram, the legends "Microsoft. Proof of License. Certificate of Authenticity." and a Product Key. In my experience, this is the number I must use when a procedure request the "Product key of Windows". I never have changed the Windows version in this computer.

On the other hand, I downloaded and run Belarc Advisor. When it ends, it displayed as Windows XP Product Key the same number shown by aGerman's Batch file (that is different than the number in the label); however, it also included this note:

"e. This is the manufacturer's factory installed product key rather than yours. You can change it to your product key here http://go.microsoft.com/fwlink/?LinkId=45668 for Windows, or here http://support.microsoft.com/?kbid=895456 for Office."

The previous link open a page that describe the procedure to "change your Windows product key".

So I don't understand now what is the "real" product key of my Windows!

Antonio

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: contain windows serial key

#12 Post by aGerman » 10 Jun 2013 17:42

I read something about it in the past.
What I remember is that none of the key finder software work properly under Win8. It seems M$ changed the encoding or they didn't even save it in the registry.
Also if you bought a computer with Windows pre-installed (and you didn't get the Windows CD) the key on the label doesn't fit with the key you'll find in the registry. The reason why is that the manufacturer have something like a site license for the same Windows version. Either the key on the label is the unique key for your computer and the one in the registry is for the original installation or vice versa. I can't remember.

Regards
aGerman

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: contain windows serial key

#13 Post by Adrianvdh » 10 Jun 2013 23:27

Thanks "aGerman" you always know what to do :]

miskox
Posts: 668
Joined: 28 Jun 2010 03:46

Re: contain windows serial key

#14 Post by miskox » 11 Jun 2013 11:08

@Aacini:

I am sure that computer manufacturers (OEMs) usualy use one licence key for their preinstalled software (OS). They make initial OS image and clone it to all the computers (same type of course). They don't have the time and/or resources to enter each serial key from the sticker.

Saso

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: contain windows serial key

#15 Post by foxidrive » 12 Jun 2013 00:22

@miscox

I'd think that an OEM that did that would lose their contract with Microsoft, if it become known.

There's a tool that will replace the key with a different one - this would be a fairly quick way to set a key.

Post Reply