0

所以每次我运行我的批处理文件时,输入计算机名称,然后输入我要查找的程序。我已经添加了“像'(word)%'这样的名称”部分,因此它不需要完全匹配来查找程序。这是我的代码:

@echo off
set /p name="Enter PC Name: "
set /p prgm="Type Part of the Program Name: "
wmic /node:%name% product where "name like '%prgm%%'" get name,version
set /p fprgm="Enter Full Program Name: "
wmic /node:%name% product where name="%fprgm%" call uninstall
pause

我不确定发生了什么,因为如果我手动进入 WMIC 并使用/node:(pc-name) product where "name like '(word)%'" get name,version它进行搜索。

4

1 回答 1

0

您需要转义一些具有特殊含义的字符才能按字面意思对待。

要将百分号 ( %) 视为批处理脚本中的常规字符, 请将其 ( )加倍%%,如下例所示:

==>type 29951224.bat
@ECHO ON >NUL
@SETLOCAL

set "name=localhost"
set "prgm=visual F"
wmic /node:%name% product where "name like '%prgm%%%'" get name,version

==>29951224.bat

==>set "name=localhost"
==>set "prgm=visual F"
==>wmic /node:localhost product where "name like 'visual F%'" get name,version
Name               Version
Visual F# 3.1 SDK  12.0.21005
Visual F# 3.1 VS   12.0.21005

==>
于 2015-04-29T19:48:03.607 回答