Wednesday, May 6, 2015

How to get and use the Windows key from UEFI/BIOS

I found myself in the situation that I needed to get the Windows key out from the ACPI in the UEFI bios and preferable get to use it in a task sequence in MDT.

There are different ways of doing this, but I wanted to do this with little code and easy to understand.

There is a nice tool created to get the key on github, created by Christian Korneck, called get_win81key. This tool gives you the key in plane text. You can get it

If I were supposed to do this manually, I now would just take that key and type it in with slmgr command or in the GUI. But I want to do this within a task in MDT.

Testing a couple of solutions without using the get_win8key with my great scripting guru colleague Håvard ( and figuring out that it cannot be done with default powershell stuff, it needs more code. Therefore, we quickly figured out that some use of the “get_win8key” files is the easiest way, but we need a way of setting the output from the file into a variable that we can use with the slmgr command.

Testing out some different solutions we ended up in this nice little line:

for /F "delims=" %%a in ('%~dp0get_win8key.exe') do set key=%%a

The get_win8key.exe files need to be located in the same folder as the cmd files that we want to run the script. We now have a variable with the result from the get_win8key

Next thing is that we want to insert that key into Windows with the “slmgr” and active it. We also want this to be done quiet. The quiet part are done with the parameter //B in cscript. We then need 2 lines of slmgr :

cscript //B %windir%\system32\slmgr.vbs /ipk %key%

cscript //B %windir%\system32\slmgr.vbs /ato

Pasting the code together it will look like this:

The next step is to copy both the get_win8key.exe and a cmd file with the script into the script folder at out MDT deployment share. I have simply called the script file “Get-Winkey.cmd”

I then need to modify the task sequence that I use to install Windows Pro (Remember that you need to have a BIOS with the key for this to work, and if you are deploying anything else then a version matching the version of the key in BIOS it will fail. Try doing it manually if you are unsure)

When was Windows started?

How long have the Server of PC been running? Sometimes you need to figure when the OS was started. As always there are different was of get...