Finding processes that are stuck or causing problems is unfortunately nothing new in the world of Windows. The good news however is that it’s super simple to kill these processes right from PowerShell.
How To Kill A Process In PowerShell
If you’ve tried to use Task Manager to kill a process but it just isn’t working, PowerShell is a fast and powerful alternative that gets the job done.
Windows creates a process for each service that is running on the operating system. Sometimes you’ll find that one service has many different processes associated with it, for instance, a Google Chrome tab.
For each process, Windows assigns a PID, or Process Identifier number. This way Windows can track each process efficiently without having to reference a long name or location file path. We’ll use this process ID to target the process in PowerShell we want to kill, and well, kill it.
- First, launch the PowerShell application. This can be done by pressing the [Windows Key] + [R] and then typing
powershellin the run box.
tasklistin the PowerShell window. Soon you’ll see a list of all the processes running on your operating system, along with relevant info such as session number and PID, and memory usage.
- Make note of the PID on the process that you want to kill and then execute the following command:
taskkill /f /PID 00000. Replace the zeros with the PID you want to kill.
Under almost all circumstances that command should kill the process. But what if you have five PIDs? 20 PIDs? 200 PIDS? Not to worry, you can kill the process by its name, which in turn will include all of its associated PIDs.
taskkill /IM loom.exe /F will kill all processes that are associated with the Loom service. After executing the command you should see a number of success messages for each PID that has been terminated.
You can right-click on the Taskbar and pull up Task Manager to find a list of running programs if you are unsure what the image name is. As long as there are no other supporting programs to restart that process, the next time you run the tasklist commands, you should no longer see that process in the list.
What is the different syntax for the taskkill command?
In most cases, you will only use a handful of this syntax to kill tasks, but there might be a time when you need to get a bit more specific when running the command. Let’s take a look at some of the most common syntax for the taskkill command.
If you’re following along in PowerShell, you can type
taskkill /? to bring up additional information.
/f Tells the command to run forcefully, and is recommended when running taskkill.
/pid Specifies the process ID. After this syntax would be the process ID that needs to be killed.
/im Represents the image name that you wish to terminate.
/u Allows you to run the command under a different user account. This represents the username that would follow.
/p Specifies the password of the user account for the /u syntax.
/s Can be followed by an IP address of a remote machine. Taskkill can be run remotely but defaults to the local machine.
/t Tells the command to end any child processes that were started by the specified process. This command is helpful for services that generate large numbers of PIDs.
/fi This sets a filter and allows you to create more complex and granular taskkill commands that utilize specific values and their condition.
Examples of terminating tasks in PowerShell
To kill the three processes with the IDs of 12, 11, and 690:
taskkill /pid 120 /pid 11 /pid 690
To forcefully end the wordpad.exe service and its related processes:
taskkill /IM wordpad.exe /F
Ends the Wordpad process on the remote computer named “Test-PC” with the username of Admin on the Acme domain that authenticates with the password 1234.
taskkill /s test-pc /u acme\admin /p 1234 /im wordpad.exe
I’m running an older operating system and don’t have taskkill
Legacy operating systems running Windows 2000/NT lack a “kill” command in their CLI. While it is still possible to get this function through a resource pack, you cannot execute it remotely. If for whatever reason you cannot upgrade to a newer operating system you can use the PsKill tool.
PsKill was developed by Microsoft so older machines could utilize the kill function. Since PsKill is based exactly on the current process kill command, all of the primary syntaxes are still the same.
Are there any tools that can help kill processes?
Frankly, it’s so easy to kill a task or process now in the modern version of Windows, it’s not worth using tools to achieve this. If you find yourself having to kill a process repeatedly this could point to larger issues such as malware or over-utilization of resources.
Process Explorer was developed by the Microsoft Windows Sysinternals team and can help you batch and kill processes. It provides a more analytical look at processes and gives you technical insight beyond what Task Manager can provide.
For instance, Process Explorer can organize and list processes, as well as cleanly display their parent services, and the DLL files that are associated with them. While most won’t need this option, it can provide technicians with additional clues as to why a process is becoming unresponsive.
Be wary of other tools that claim to “clean” or “optimize” your processes. These often come with registry cleaners that can break applications or built-in spyware that sells your browsing habits.
What should I do when a process goes into “not responding?”
Services or processes that go into a not responding state is a common occurrence in Windows PC. While it isn’t something that should happen often, it’s one of the more frequent problems you’ll encounter in a Windows environment.
The best thing to do is to kill the process through either Task Manager, or PowerShell as described above, and relaunch the application if needed. Make a quick note of your system’s resources before you kill the process.
Was your memory maxed out? Did you run out of disk space? Many times applications and services will lock up due to not having enough resources. This is common among photo and video software as well as video games that demand a large number of resources from your machine.
If a process continuously crashes, and running a kill process in PowerShell doesn’t fix it, consider reinstalling the associated program. While this isn’t the most technical approach, it’s often the quickest way to get back up and running.
Event Viewer can also play a role in helping determine why a process needs to be killed. Many times there are events that are recorded before the process is killed that help paints a picture and provide some background information as to what went wrong.
Another quick troubleshooting step is to run a proper virus scan on your computer in Safe Mode. In rare circumstances, viruses can actually purposefully prevent certain applications from working correctly. If you see an unknown process continuously re-create itself and you’re experiencing other strange issues such as slowness and random webpage redirects
In contrast to that, it can be a good idea to temporarily disable your antivirus and test out the application again. If the process does not go unresponsive after the antivirus software is disabled, it’s likely related.
Check your antivirus blocking history and whitelist the application if you’re confident this has been done in error. Some enterprise levels antivirus software has more granular settings that can cause this such as persistent file and integrity scanning. Consider testing these settings individually.
Killing processes on stubborn software
Admins sometimes find themselves supporting outdated and antiquated software with no other alternatives available. This can be frustrating and cause unnecessary tickets to hit the NOC. In these rare circumstances sometimes empowering the user to fix the problems is the best option, until a more permanent fix has been identified.
Many times when a process is not responding, it will be frozen or not visible from the GUI. Relaunching the application normally does nothing if the process is already running, causing users to call in or create tickets.
While we can’t rely on users to run PowerShell commands, we can make running the command easier for them. If your network environment allows for it, consider creating a batch script that kills the problem process for the user.
taskkill /f /im someprocess.exe
Putting the above text in a notepad and saving it as a .bat file will execute the command when launched. You can of course put multiple commands per line to kill different processes if necessary. By naming the script something user-friendly and placing it on their desktop, you can help educate users on how to kill the process themselves with this shortcut.
For most of us, pulling up a task manager is the quickest way to kill a stuck process. Sometimes killing a process through PowerShell is necessary due to a graphical glitch or a need for a more precise command.
If this helped fix your issue, be sure to let us know in the comments below.