WMIC 产品 where "name like..." - "no instances available" if 运行 in batch file

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

我想了解特定工作站上运行正在使用的 Outlook 版本。如果我手动 运行

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

在命令行中,它有效。但是如果我从批处理文件中 运行 它,它 returns "No instance(s) available"。我什至从批处理文件中删除了所有其他内容,所以只剩下这一行 - 我仍然得到相同的结果。我错过了什么吗?

在批处理脚本文件中:

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

为了证明,在你的批处理文件中尝试下一步:

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

您应该会看到下一个 ECHOed 命令,与从命令提示符键入的命令相同:

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

解释,阅读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: %%

同时阅读 How does the Windows Command Interpreter (CMD.EXE) parse scripts?(整个线程)。