How to Stop a Running Service or a Program from Command Prompt or PowerShell.
If you want to learn how to stop a running service or a program from command prompt or from the Windows PowerShell, then continue reading this tutorial. The usual way to terminate a running process in Windows, is to open the Task Manager, to right click on the process and to select 'End Task' or "End process tree". Additionally, if you want to Stop a service, you have to navigate to services and to select the "Stop" option, after right-clicking on the service.
However, another useful way to terminate a running service or program, is to use the Command Line or the PowerShell, especially in cases where you cannot terminate the process using Task Manager.
How to Terminate any Running Process (Program or Service) from Command prompt or PowerShell.*
* Note: Keep in mind, that critical Windows services cannot be stopped in any way.
Step 1. Find the Name or the PID of the Running Process.
In order to stop an application or service from the command prompt or from the PowerShell, you need to know the Process Name or the Process Identifier (PID)*.
* Note: The Process Identifier (PID), is a unique number that identifies each of the running processes on the Operating System.
To find the Name or the Name or the PID of a process, use one of the following ways:
Option 1. Find the Process Name & PID from Task Manager.
The first and most easy way to find the name and the PID of a process in Windows, is from the Details tab in Task Manager. Additionally, if you want to find out the Name & PID of a service, select the Services tab.
Option 2. Find the Process Name & PID from Command Prompt or PowerShell.
1. To view the Name and the PID of all the running processes, type the following command (and press Enter), either in Command Prompt or in PowerShell: *
- tasklist
2. Now notice the PID the process that you want to stop and continue to step 2. *
* TIPS:
1. To view a list of all the PIDs of a running program (process), give this command:
- tasklist /fi "imagename eq ProcessName.exe"
e.g. to view all the PIDs of the "Chrome.exe" process, type:
- tasklist /fi "imagename eq chrome.exe"
2. To view the PID of a specific service type:
- sc queryex ServiceName
e.g. to view all the PID of the "BITS" service process, type:
- sc queryex bits
Step 2. Terminate a Process from the Command Prompt or the PowerShell.
After finding the Name or the PID of the process/service that you want to stop, proceed to stop it by following the instructions below:
Part 1. How to Kill a Process from Command Prompt.
To terminate a process from command prompt, you can use either its name or its PID.
A. To terminate a running process by using its PID from Command Prompt:
1. Open Command Prompt as Administrator.
2. Type the following command and press Enter:*
- taskkill /F /PID ProcessPID
* Note: Where ProcessPID = the PID of the process that you want to stop. e.g.: If you want to terminate the "notepad.exe" process with PID 1908, type:
- taskkill /F /PID 1908
B. To force close all instances of a running service or application, by using its name:
1. Open Command Prompt as Administrator.
2. Type the following command and press Enter:*
- TASKKILL /F /IM ProcessName /T
* Note: Where ProcessName = The name of the application that you want to stop as listed in the "Image Name" column. e.g.: If you want to terminate all the instances of the "Chrome.exe" application, type:
- TASKKILL /F /IM chrome.exe /T
Part 2. How to Kill a Process from PowerShell.
To stop a process from PowerShell, you can use either its name or its PID.
A. To force stop a running process of a service or application, by using the PID:
1. Open PowerShell as Administrator.
2. Type the following command and press Enter: *
- kill -id ProcessPID
* Note: Where ProcessPID = the PID of the process that you want to stop. e.g.: If you want to terminate the "notepad.exe" process with PID 396, type:
-
kill -id 396
B. To stop a running process or service, by using its name from PowerShell:
- Stop-Process -Name "ProcessName"
* Note: Where ProcessName = The name of the application that you want to stop as listed in the "Image Name" column without the ".exe extension". e.g.: If you want to terminate all the instances of the "Chrome.exe" application, type:
- Stop-Process -Name "chrome"
That's it! Let me know if this guide has helped you by leaving your comment about your experience. Please like and share this guide to help others.
We're hiring
We're looking for part-time or full-time technical writers to join our team! It's about a remote position that qualified tech writers from anywhere in the world can apply. Click here for more details.
PhredE
October 3, 2021 @ 1:13 pm
Okay, good. Now how do we do it from a batch file.
Doing it programmatically without knowing the PID?
Thx.
lakonst
October 4, 2021 @ 9:34 am
At this case, if you know the service that starts the process then you can disable the service.