batch file to check if exe is running if so taskkill

user2690655 picture user2690655 · Aug 16, 2013 · Viewed 24.1k times · Source

I'm having problems with the firefox Flashplayerplugin eating up too much ram and lagging my system when it's not in use. The only solution I found was killing the flashplayerplugin while using firefox, uninstalling, reinstalling or a fresh firefox install or new profile doesn't solve it; however, it's becoming very tedious having to check taskmanager all the time and kill it and the flashplayerplugin always seems to start on it's own.

The question I have is if it's possible to create a batch file to check if FlashPlugin_11_8_800_94.exe is running and kill it after a period of time (5-10 seconds) and continue running the batch file actively, in a loop, scanning if FlashPlugin_11_8_800_94.exe has started again, then kill it after 5 - 10 seconds, rinse and repeat?

Edit:

Found a batch file and modified it, but also seems to be missing some perimeters to actively search if it's running, even when it is not. It doesn't work either way though.

@echo off

:search
TASKLIST|FIND "FlashPlayerPlugin"
IF %ERRORLEVEL% = 0 THEN (GOTO found)
TIMEOUT /T 5
GOTO search

:found
taskkill /im FlashPlayerPlugin_11_8_800_94.exe

--

This batch file doesn't work either.

set tasklist=%windir%\System32\tasklist.exe
set taskkill=%windir%\System32\taskkill.exe

-------------------------------------------------------
:STOPPROC
    set wasStopped=0
    set procFound=0
    set notFound_result=ERROR:
    set procName=%1
    for /f "usebackq" %%A in (`%taskkill% /IM %procName%`) do (
      if NOT %%A==%notFound_result% (set procFound=1)
    )
    if %procFound%==0 (
      echo The process was not running.
      goto :EOF
    )
    set wasStopped=1
    set ignore_result=INFO:
:CHECKDEAD
    "%windir%\system32\timeout.exe" 3 /NOBREAK
    for /f "usebackq" %%A in (`%tasklist% /nh /fi "imagename eq %procName%"`) do (
      if not %%A==%ignore_result% (goto :CHECKDEAD)
    )
    goto :EOF
-------------------------------------------------------

:MAIN 

call :STOPPROC FlashPlayerPlugin_11_8_800_94.exe

Answer

npocmaka picture npocmaka · Aug 17, 2013
taskkill /im FlashPlugin_11_8_800_94* /f >nul 2>&1