选择任何:
阅读如何 FINDSTR
将设定 ERRORLEVEL
@ECHO OFF
SETLOCAL EnableExtensions
set "_product=abc123"
rem set "_product=avg zen"
echo 'redirection' way
(wmic product get name| findstr /i /C:"%_product%")&&(
echo %_product% exists
rem uninstall here
)||(
echo %_product% no instance
)
echo 'if errorlevel' way
wmic product get name| findstr /i /C:"%_product%"
if errorlevel 1 (
echo %_product% no instance
) else (
echo %_product% exists
rem uninstall here
)
echo 'direct call' way
wmic product where "name='%_product%'" call uninstall/nointeractive
输出为 set "_product=abc123"
:
==> D:\bat\SU\1087355.bat
'redirection' way
abc123 no instance
'if errorlevel' way
abc123 no instance
'direct call' way
No Instance(s) Available.
输出为 set "_product=avg zen"
但随着 '直接呼叫'的方式 跳过:
==> D:\bat\SU\1087355.bat
'redirection' way
AVG Zen
avg zen exists
'if errorlevel' way
AVG Zen
avg zen exists