8

I want to find what version of Outlook is running on specific workstations. If I manually run

wmic /node:"hostname" product where "Name like '%Office Outlook%'" get Name

in a command line, it works. But if I run it from a batch file, it returns "No instance(s) available". I've even stripped everything else out of the batch file, so only this line is left - and I still get the same result. Am I missing something?

user2132386
  • 95
  • 1
  • 1
  • 4

1 Answers1

18

In a batch script file, escape your %s by prefacing each with another % as follows:

wmic /node:"hostname" product where "Name like '%%Office Outlook%%'" get Name

For proof, try next in your batch file:

echo ON
wmic /node:"hostname" product where "Name like '%%Office Outlook%%'" get Name
pause

You should see next ECHOed command, the same as it would be typed from command prompt:

wmic /node:"hostname" product where "Name like '%Office Outlook%'" get Name
:::::::::::::::::::::::::::::
::: some wmic output here :::
:::::::::::::::::::::::::::::
Press any key to continue . . .

For explanation, read Syntax : Escape Characters, Delimiters and Quotes

Escaping Percents

The % character has a special meaning for command line parameters and FOR parameters.
To treat a percent in a batch script file as a regular character, double it: %%

Read How does the Windows Command Interpreter (CMD.EXE) parse scripts? (entire thread) as well.

Oskar Austegard
  • 4,599
  • 4
  • 36
  • 50
JosefZ
  • 28,460
  • 5
  • 44
  • 83