Terminating a windows process with a Batch File

You might come acrosss a situation where you would want to terminate a process with a batch file. Below is a sample script to do so.

@ echo off
REM Sample Script to look for a process and kill another process if earlier process is not running
REM Error level 1 means application is not running

set findProcess=NOTEPAD.EXE
set killProcess=NOTEPAD++.EXE

tasklist /FI "IMAGENAME eq %findProcess%" | FINDSTR "%findProcess%"
if ERRORLEVEL 1 (
echo "%findProcess% Application is Not Running,Looking for %killProcess%"
	tasklist /FI "IMAGENAME eq %killProcess%" | FINDSTR "%killProces%"
	if ERRORLEVEL 1 (
		echo "%killProcess% is not Running, So Quitting Now!"
	) else (
		echo "%killProcess% is running, killing it now"
		taskkill /F /IM %killProcess%
	)		 	
) else (
	echo "Application is  running, not doing anything"
)

You may also like...