Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WMIC product where "name like..." - "no instances available" if run in batch file

Tags:

wmic

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?

like image 983
user2132386 Avatar asked Sep 27 '16 18:09

user2132386


People also ask

How do I get my WMIC product name?

By Typing “wmic product get name” will shows you a list of all application names which is installed on your machine. Use “wmic product get /?” to see the parameters including the output formatting with all other attributes.

What is WMIC command in CMD?

The Windows Management Instrumentation Command line (WMIC) is a software utility that allows users to performs Windows Management Instrumentation (WMI) operations with a command prompt.

What is the replacement for WMIC?

The WMIC tool is deprecated in Windows 10, version 21H1 and the 21H1 General Availability Channel release of Windows Server. This tool is superseded by Windows PowerShell for WMI.

Is WMI and WMIC the same?

What is WMIC? The Windows Management Instrumentation (WMI) Command-Line Utility (WMIC) is a command-line utility that allows users to perform WMI operations from a command prompt. WMI is an interface providing a variety of Windows management functions.


1 Answers

In a batch script file:

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.

like image 167
JosefZ Avatar answered Sep 21 '22 21:09

JosefZ