How to manually forcefully stop a hung Windows service process that hangs at “Stopping” or “Not responding”? Most Windows administrators have faced a problem, when they try to stop (restart) a service, but it gets stuck with the Stopping status. You won’t be able to stop this service from the Service management console (services.msc), since all control buttons for this service become inactive. The easiest way is to restart Windows, but it is not always acceptable. Let’s consider an alternative way, which allows to forcefully kill a stuck Windows service or process without system reboot.
If within 30 seconds after trying to stop the service, it doesn’t stop, Windows displays this message:
Error 1053: The service did not respond in a timely fashion.
If you try to stop such a service from the command prompt: net stop wuauserv
, a message appears:
The service is starting or stopping. Please try again letter.
How to Terminate a Hung Windows Service Process Using TaskKill?
The easiest way to stop a stuck service is to use taskkill. First of all, you need to find the PID (process identifier) of the service. As an example, let’s take Windows Update service, its system name is wuauserv
(you can check the name in the service properties in the services.msc console).
Run this command in the elevated command prompt (it is important, or access denied error will appear):
sc queryex wuauserv
In our case the PID of the wuauserv service is 816.
To force stop a hung process with the PID 816, run the command:
taskkill /PID 816 /F
You can stop a hung service more elegantly without checking the service PID manually. The taskkill utility has the /FI option, which allows you to use a filter to select the necessary services or processes. You can shutdown a specific service with the command:
taskkill /F /FI "SERVICES eq wuauserv"
Or you can skip the service name at all and killing all services in a hung state with the command:
taskkill /F /FI "status eq not responding"
After this, the service that hangs in the Stopping status should stop.
PowerShell: Stop Windows Service with Stopping Status
You can also use PowerShell to force the service to stop. Using the following command you can get a list of services in the Stopping state:
Get-WmiObject -Class win32_service | Where-Object {$_.state -eq 'stop pending'}
The Stop-Process cmdlet allows to terminate the processes of all found services. Let’s combine both operations into a loop and get a script that automatically terminates all the processes of the stuck services:
$Services = Get-WmiObject -Class win32_service -Filter "state = 'stop pending'"
if ($Services) {
foreach ($service in $Services) {
try {
Stop-Process -Id $service.processid -Force -PassThru -ErrorAction Stop
}
catch {
Write-Warning -Message " Error. Error details: $_.Exception.Message"
}
}
}
else {
Write-Output "No services with 'Stopping'.status"
}
Identify a Hang Process Using Resmon
You can detect the process that caused the service freeze using the resmon (Resource Monitor).
- In the Resource Monitor window, go to the CPU tab and locate the hung service process;
- Select the item Analyze Wait Chain from the context menu;
- In the new window, you will most likely see that your process is waiting for another process. End the process. If you are waiting for the svchost.exe or another system process, you don’t need to terminate it. Try to analyze the wait chain for this process. Find the PID of the process that your svchost.exe is waiting for and kill it.
Process Explorer: Killing a Hung Process Running in SYSTEM Context
Even the local administrator cannot terminate some processes that run in the SYSTEM context. The fact is that the admin account simply haven’t permissions on some processes or services. To stop such a process (services), you need to grant permissions to the service (process) to the local Administrators group, and then terminate them. To do this, we will need two small tools: psexec.exe and ProcessExplorer (available on the Microsoft website).
- To run ProcessExplorer with the system privileges (runas SYSTEM), run the utility in this way:
PSExec -s -i ProcExp.exe
- In the Process Explorer process list, find the stuck service process and open its properties;
- Go to the Services tab, find your service and click the Permissions button;
- Grant the Full Control right in the service permissions for the Administrators group. Save the changes;
- Now try to stop the service process. Please note, that the permission on the service is granted temporarily, prior to its restart. To grant permanent permissions on service follow the article Set permissions on a Windows service.
2 comments
A product called System Frontier makes this super easy. When you view a list of services on a remote machine that are stuck in a “Start Pending” or “Stop Pending” state, you’ll have a button available to kill the service process. No need to look up the PID. It uses RBAC to determine if you’ve been granted the appropriate access to perform the action and there’s a full audit trail.
Terrific information very well laid out. Thank you.