• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2981
  • Last Modified:

Can't Capture WMIC DATAFILE output to variable on Windows 7


I am using the following WMIC command to retrieve the version info from a file.  For this example, I am using iexplore.exe

When I execute the command interactively in a command window on Windows XP and Windows 7, I get identical outputs.

Command:
WMIC DATAFILE WHERE "Name='%SYSTEMDRIVE%\\program files\\internet explorer\\iexplore.exe'" GET Version

Output:
Version
8.0.7601.17514


When I try to capture the output thru a "for /f" loop, it works for Windows XP, but I can't get it work for Windows 7.

I have tried variations with "setlocal EnableDelayedExpansion",but with no luck.

Here is the contents of the bat file, IE_version.bat


@echo off
for /f "skip=1 tokens=1 delims= " %%g in ('WMIC DATAFILE WHERE ^"Name^='%SYSTEMDRIVE%\\program files\\internet explorer\\iexplore.exe'^" GET Version') DO (
set IEVER=%%g
)
echo IE Version: %IEVER%


Here is the output on Windows XP:

IE Version: 8.00.6001.18702


Here is the output on Windows 7:

IE Version:


I must be missing something obvious, but cannot find it!

Thanks
0
MichaelScottPaper
Asked:
MichaelScottPaper
  • 3
  • 2
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Hi Michael,

Here's a working W7 version for you:
@echo off
for /f "skip=2 delims== tokens=2" %%g in ('WMIC DATAFILE WHERE ^"Name^='%SYSTEMDRIVE%\\program files\\internet explorer\\iexplore.exe'^" GET Version /value') DO (
set IEVER=%%g
)
echo IE Version: %IEVER%

Open in new window


Output:

C:\Temp>ver
Microsoft Windows [Version 6.1.7601]

C:\Temp>getiever.cmd
IE Version: 8.0.7601.17514

C:\Temp>
0
 
MichaelScottPaperAuthor Commented:
gerwinjansen,

I confirm it works for Windows 7.  

Unfortunately, for Windows XP, its now not parsing just the version number and is also outputting the extra information "(xpsp.080413-2105)"

I am hoping to have one piece of code to provide the same output without having to have extra code to determine operating system first.


D:\>getiever.cmd
IE Version: 6.00.2900.5512 (xpsp.080413-2105)

D:\>ver

Microsoft Windows XP [Version 5.1.2600]

D:\>



D:\>getiever.cmd
IE Version: 8.0.7601.17514

D:\>ver

Microsoft Windows [Version 6.1.7601]

D:\>
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I understand :) Can you show me your output of just the WMIC command on WinXP?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
telczj9Commented:
MichaelScottPaper,

try this, it should work in WinXP and Win7

@echo off
ver | find "XP" > NUL
IF not errorlevel 1 (
  for /f "skip=1 tokens=1 delims= " %%g in ('WMIC DATAFILE WHERE ^"Name^='%SYSTEMDRIVE%\\program files\\internet explorer\\iexplore.exe'^" GET Version') DO (
  set IEVER=%%g
  )
) else (
  for /f "skip=2 delims== tokens=2" %%g in ('WMIC DATAFILE WHERE ^"Name^='%SYSTEMDRIVE%\\program files\\internet explorer\\iexplore.exe'^" GET Version /value') DO (
  set IEVER=%%g
  )
)
echo IE Version: %IEVER% 

Open in new window


This is the output on both win7 and winXP:
C:\>ver

Microsoft Windows [Version 6.1.7601]

C:\>getiever.cmd
IE Version: 8.0.7601.17514

C:\>


C:\>ver

Microsoft Windows XP [Version 5.1.2600]

C:\>getiever.cmd
IE Version: 7.00.6000.17103

Open in new window



Cheers!
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Found it already, this version works both for XP and W7, without the need for 'ver':

@echo off
for /f "skip=2 tokens=2 delims== " %%g in ('WMIC DATAFILE WHERE ^"Name^='%SYSTEMDRIVE%\\program files\\internet explorer\\iexplore.exe'^" GET Version /value') DO (
set IEVER=%%g
)
echo IE Version: %IEVER%

Open in new window


XP output

C:\Temp>getiever.cmd
IE Version: 6.00.2900.5512

W7 output

C:\Temp>getiever.cmd
IE Version: 8.0.7601.17514
0
 
MichaelScottPaperAuthor Commented:
gerwinjansen,

Excellent!

This does exactly what I want with minimal code and I have learned something new!  

Accepting Solution.

Thank you!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now