Chrismage
Chrismage

Reputation: 129

Process kill count with a .bat file

I'm trying to kill a certain process in windows when the process count exceeds the value i have set.

set a=tasklist | find /I /C "example.exe"
set b=3
if a GTQ b ( 
TASKKILL /FI "USERNAME eq %USERNAME%" /IM example.exe /F /T)

The above is what I have been able to do until now but it doesn't seem to work Thanks in advance all :)

Upvotes: 1

Views: 95

Answers (1)

Magoo
Magoo

Reputation: 80113

for /f %%a in ('tasklist ^| find /I /C "example.exe"') do set /a a=%%a
set /a b=3
if %a% GEQ %b% ( 

the for /f runs the command in 'single quotes' which requires the | redirector to be escaped. The result of the single-quoted command is assigned to %%a and thence to a

set /a is an arithmetic set

%var% evaluates to the contents of the nominated variable var

geq is the greater than or equal to operator.

Upvotes: 1

Related Questions