I've a batch that kill certain processes. After starting it, I want to hide Ignoring: <ProcessName>
and display only Terminating: <ProcessName>
, so how I can do this ?
@echo off
cls
title prockiller
setlocal
:Whitelist
set "whitelist=Microsoft Avast Panda ESET Kaspersky Avira AVG Bitdefender Malwarebytes Norton McAfee GAS IBM"
:Analyze
for /f "tokens=2 delims=," %%I in (
'wmic process get executablepath^,status /format:csv ^| find "\"'
) do (
set "proc=%%~I"
setlocal enabledelayedexpansion
wmic datafile where "name='!proc:\=\\!'" get manufacturer 2>nul | findstr /i "%whitelist%" >nul && (
echo Ignoring: %%~nI
) || (
echo Terminating: %%~nI && taskkill /im "%%~nxI" /f /t >nul 2>&1
)
endlocal
)
Thanks in advance.
Here's a quick untested version:
@Echo Off
Title Process killer with a whitelist
Set "IPL=Avast AVG Avira BitDefender ESET GAS IBM Kaspersky Malwarebytes"
Set "IPL=%IPL% McAfee Microsoft Norton Panda"
For /F "Skip=1 Delims=" %%A In (
'WMIC Process Where "Not ExecutablePath Is Null" Get ExecutablePath'
) Do For /F "Delims=" %%B In ("%%~A") Do Call :Sub %%~B
Timeout -1
Exit/B
:Sub
Set "proc=%*"
For %%A In ("%proc:\=\\%") Do (
WMIC DataFile Where "Name='%%~A' And Not Manufacturer Is Null"^
Get Manufacturer|FindStr/IVX "Manufacturer"|FindStr/I "%IPL%">Nul||(
Echo Terminating "%proc%"
Echo=TaskKill /F /IM "%%~nxA" /T))
Remove Echo=
from the last line, and optionally the Timeout -1
line, if the console output looks okay.