0

I'm looking to leverage this command to detect the version and set a script to remove any version less than a certain number. The output typically includes the word Version and the number. How do I select only the second line or output only the numbers.

wmic datafile where name='c:\windows\system32\notepad.exe' get version
npocmaka
  • 55,367
  • 18
  • 148
  • 187

2 Answers2

0

It looks like WQL does not have any type of rownum keyword or string functions. You could use a batch file to process the output for you.

Assuming your output is like:

version 1
version 2
version 3

Put the following in a batch script:

@echo off
for /F "tokens=*" %%a in ('more') do call :Process %%a

:Process
echo %2
goto :eof

Pipe your output to it:

wmic datafile where name='c:\windows\system32\notepad.exe' get version | batch.bat

If your output is:

version1
version2
version3

use:

@echo off
for /F "tokens=*" %%a in ('more') do call :Process %%a

:Process
set v=%1
echo %v:~7,8%
goto :eof
Josh H
  • 264
  • 1
  • 10
0

I would place the WMIC command into a For loop and capture its output as a variable.

@Echo Off
Set "ExePath=C:\Windows\System32\notepad.exe"
For /F "Skip=1 Delims=" %%A In ('WMIC DataFile Where "Name='%ExePath:\=\\%'"^
 Get Version 2^>Nul') Do For /F %%B In ("%%A") Do Set "ExeVer=%%B"
Echo(%ExeVer%
Pause

Just modify the fullpath target file on line 2 as necessary.

Compo
  • 36,585
  • 5
  • 27
  • 39