Reputation: 1455
I have batch file:
@echo off
set vers=0.0
FOR /F "USEBACKQ" %%A IN (`wmic datafile where name^="C:\\Windows\\System32\\msiexec.exe" get Version`) do (set vers=%%A)
echo %vers%
@pause
Windows XP (SP2):
3.0.3790.2180
Windows Vista (SP1), Windows XP (x64):
ECHO is off.
How to fix that in both situations the batch file executed correctly?
Upvotes: 1
Views: 141
Reputation: 70923
@echo off
setlocal enableextensions
set vers=0.0
FOR /F "tokens=2 delims== usebackq" %%A IN (
`wmic datafile where name^="C:\\Windows\\System32\\msiexec.exe" get Version /value ^| find "="`
) do set "vers=%%A"
echo %vers%
endlocal
pause
It just asks wmic to output data in the format key=value
, filters the output of the wmic command searching only lines with =
and splits the lines using this character as token delimiter. The first token (the key) is ignored, and second token (the value) is assigned to vers
variable.
Upvotes: 3