Reputation: 8621
I'm attempting to make a batch script to pull the windows product key from BIOS so the computer can be properly activated in a production environment.
The command I am running to get the key is wmic path SoftwareLicensingService get OA3xOriginalProductKey > text.txt
which creates a text file called text.txt which contains this:
OA3xOriginalProductKey
xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
(Note some random spaces in there after each line)
The problem is I need JUST the xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
part, but I am having a terrible time doing that.
I have tried the following:
for /F "skip=10 delims=" %%i in (text.txt) do echo %%i
for /f "tokens=1*delims=:" %%G in ('findstr /n "^" text.txt') do if %%G equ 2 echo %%H
for /f "tokens=*" %%a in (text.txt) do call :processline %%a
:processline
echo line=%*
and last but not least
for /F "tokens=2" %%i in (text.txt) do echo %%i %%j %%k
As I said I am having a terrible time and am very much a noob with for /f - I have no idea where I am going wrong or what to do.
Upvotes: 2
Views: 4237
Reputation: 56188
you can use for
to get the output of a command.
@echo off
For /f "tokens=2 delims=," %%a in ('wmic path SoftwareLicensingService get OA3xOriginalProductKey^,VLRenewalInterval /value /format:csv') do set key=%%a
echo %key%
Using another wmic
token (here VLRenewalInterval
) is one of several methods to get rid of the ugly wmic line endings (the desired token has no line ending).
Upvotes: 3