Escolha qualquer:
Leia como FINDSTR
definirá 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
Saída para set "_product=abc123"
:
==> D:\bat\SU87355.bat
'redirection' way
abc123 no instance
'if errorlevel' way
abc123 no instance
'direct call' way
No Instance(s) Available.
Saída para set "_product=avg zen"
, mas com 'maneira de chamada direta' ignorada:
==> D:\bat\SU87355.bat
'redirection' way
AVG Zen
avg zen exists
'if errorlevel' way
AVG Zen
avg zen exists