How to Stop a Running Process From a Batch File
This article illustrates how we can stop a running process from a Batch file in Windows. We use Batch’s taskkill
command to kill a running process.
Note that the command will only be executed if the specified process is open.
Batch File Kill Process if Running
Killing a process gives users of Microsoft Windows XP Professional, Windows 2003, or later the ability to terminate a task from a Windows command line using the process id (PID) or image name. The TASKKILL
command is employed in this situation.
Here is an example.
taskkill /IM notepad.exe
The command above will terminate the opened notepad
task. Note that the above command may fail and prompt you to save changes.
To remedy this, we can forcibly close notepad
as illustrated below.
taskkill /F /IM notepad.exe
We can also use the process id (PID) as illustrated below.
taskkill /pid 9415
The command above will kill the process with the id 9415
.
In conclusion, we can use the taskkill
command to stop the open process from a Batch file in Windows. We have discussed the various ways of killing a process using a Batch file.
Keep in mind that the script will execute successfully if the specified process is open and running.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn