Mike
Mike

Reputation: 199

Batch scripting, mutlple finds and multple do sets

At the moment I am running the following to get some information from 'systeminfo', however it needs to run systeminfo twice which takes some time. How would I be able to do multple 'Find"XXX" do sets'?

For /f "delims=" %%A IN ('systeminfo ^| Find "OS Name"') DO Set "VarA=%%A"
For /f "delims=" %%A IN ('systeminfo ^| Find "BIOS Version"') DO Set "VarB=%%A" 

Any help is greatly appreciated.

Upvotes: 1

Views: 52

Answers (3)

Mike
Mike

Reputation: 199

Thanks for the replies guys.

I wanted to set the bit version windows the batch file would run on, I figured it out ages ago but thought I would post it here for those that came across it:

echo %PROCESSOR_ARCHITECTURE% | find "64" > NUL
If %ERRORLEVEL% equ 0 (Set bit=64) else (Set bit=32)

Thanks!

Upvotes: 0

dbenham
dbenham

Reputation: 130859

I too would use WMIC, but there is a simple solution if you want to use SYSTEMINFO - use FINDSTR with two /C:"search strings"

for /f "tokens=1,2*" %A in ('systeminfo ^| findstr /c:"OS Name" /c:"BIOS Version"') do set "%A=%C"

The above will define two variables on an English machine: OS and BIOS.

Upvotes: 0

JosefZ
JosefZ

Reputation: 30123

Next code snippet could work (note set commands are merely ECHOed for debugging purposes; remove capitalized ECHO no sooner than debugged):

For /f "delims=" %%A IN ('systeminfo') DO (
   For /F "delims=" %%G IN ('echo %%A ^| Find /I "OS Name"') Do ECHO Set "VarA=%%A"
   For /F "delims=" %%G IN ('echo %%A ^| Find /I "BIOS Version"') DO ECHO Set "VarB=%%A" 
)

However, follow Stephan's advice and parse wmic output rather (do not forget /value option). To do that correctly, note great Dave Benham's article WMIC and FOR /F: A fix for the trailing <CR> problem

Upvotes: 2

Related Questions