Search code examples
windowsbatch-filecommandwmic

Activating Windows 8.1 with BIOS product key with batch command


I need to deploy windows images to several computers that came with Windows 8.1. I did manage to inject drivers and updates and some necessary softwares to the installation image, but somehow it seems that just installing Windows won't activate the operating system, and I have to find the license keys embedded in the BIOS and activate them manually.

I found out that wmic path softwarelicenseingservice get oa3xoriginalproductkey could be used to extract the product key from the bios, and I am thinking about composing a batch file that uses this command in joint with slmgr -ipk and slmgr -ato, and then make it run as the firstlogon command.

The trouble is that I don't know a lot about batch syntax, and I am having a hard time assigning the product key as a variable and passing it over to slmgr commands.

It seems that the wmic command returns the result as:

OA3xOriginalProductKey  
XXXXX-XXXXX-XXXXX-XXXXX-XXXXX      
<blank line>

So there it returns the product key in a three line text, with the actual useful information sandwiched between other strings. How can I just get the middle(or second) line from this text and assign it as a variable?


Solution

  • Maybe this will work for you. Note it does involve a temporary text file.

    wmic path softwarelicenseingservice get oa3xoriginalproductkey > temp.txt
    3<temp.txt (
    set /p var= <&3
    set /p var= <&3
    )
    del temp.txt
    Echo %var%
    

    Which will always extract the second line of output from the command. I have tested this with the data you provided and it outputted XXXXX-XXXXX-XXXXX-XXXXX-XXXXX. TO access this variable always refer to it as %var%.