远程获取已安装程序列表时找不到实例
No Instance(s) Found when Remotely getting a list of installed programs
所以每次我 运行 我的批处理文件时,我都会输入计算机名称,然后输入我要查找的程序。我添加了 "name like '(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
进行搜索,它会起作用。
您需要 escape some characters with special meaning 才能按字面意思对待。
要将百分号 (%
) 视为批处理脚本中的常规字符,将其加倍 (%%
),如下例所示:
==>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
==>
所以每次我 运行 我的批处理文件时,我都会输入计算机名称,然后输入我要查找的程序。我添加了 "name like '(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
进行搜索,它会起作用。
您需要 escape some characters with special meaning 才能按字面意思对待。
要将百分号 (%
) 视为批处理脚本中的常规字符,将其加倍 (%%
),如下例所示:
==>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
==>