Reputation: 111
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?
Upvotes: 2
Views: 8138
Reputation: 1
This is what I needed.
It works perfect.
for /f "tokens=2 delims='='" %%K IN ('wmic path softwarelicensingservice get OA3xOriginalProductkey /value') do set pk=%%K
slmgr.vbs /ipk "%pk%"
slmgr.vbs /ato
Upvotes: 0
Reputation: 1
cscript.exe C:\Windows\System32\slmgr.vbs /upk
cscript.exe C:\Windows\System32\slmgr.vbs /cpky
for /f "tokens=2 delims='='" %%K IN ('wmic path softwarelicensingservice get OA3xOriginalProductkey /value') do set pk=%%K
cscript.exe C:\Windows\System32\slmgr.vbs /ipk %pk%
cscript.exe C:\Windows\System32\slmgr.vbs /ato
cscript.exe C:\Windows\System32\slmgr.vbs /dli
save this as batch file and try
Upvotes: 0
Reputation: 1212
Here's how i would do it
Logon scripts accept powershell scripts which has much more features and strength in it than the old batch files.
$key = Get-WmiObject -Class SoftwareLicensingService |
Select-Object OA3xOriginalProductKey | foreach { "{0}" -f $_.OA3xOriginalProductKey }
with this command, you get your ProductID into the $key variable and free to do any manipulation you'd like with it
Upvotes: 0
Reputation: 6610
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%
.
Upvotes: 1