Windows administrators may encounter an issue where, when attempting to stop or start a service in the services.msc
management snap-in, the service gets stuck in the “Stopping
” or “Starting
” state. In this case, the service control buttons (Start, Stop, and Restart) will be grayed out and inactive. Let’s learn how to forcefully kill a stuck Windows service or process without a system reboot.
If, within 30 seconds after trying to stop the service, it doesn’t stop, Windows displays this message:
Windows Could not stop the xxxxxx service on Local Computer Error 1053: The service did not respond in a timely fashion.
or:
Windows could not stop the Service on Local Computer. [SC] ControlService Error 1061: The service cannot accept control messages at this time.
The hung service does not respond to attempts to start or stop it from the command prompt. For example, the command net stop wuauserv
will return:
The service is starting or stopping. Please try again later.
How to Force Kill a Stuck Windows Service Using TaskKill
You can use the taskkill console command to stop a stuck service. It allows stopping a service process by its process identifier (PID). Open the services.msc
MMC snap-in, find the stuck service, and open its properties. Copy the Service Name value.
Then, run the following command in the command prompt as an administrator:
sc queryex wuauserv
In our case, the PID of the wuauserv service is 9186. Now, use the taskkill command to force kill the stuck process with the PID 9186:
taskkill /PID 9168 /F
SUCCESS: The process with PID 9168 has been terminated.
After terminating the hung service process, you can restart it using the sc start servicename
command or through the service management console.
Instead of manually searching for the PID of the service process, you can use a more elegant method. The /FI argument in the taskkill command lets you filter processes by service name. In this case, rather than performing two actions (searching for the PID and killing the process), one command is sufficient:
taskkill /F /FI "SERVICES eq wuauserv"
Or you can kill all services in a hung state with the command:
taskkill.exe /F /FI "status eq NOT RESPONDING"
The taskkill can also be used to forcefully stop a hung service on a remote computer.
TASKKILL /S 192.168.12.15 /F /FI "SERVICES eq wuauserv" /U MyDomain\user
Force Stop a Stuck Windows Service with PowerShell
With PowerShell, you can list all services stuck in the stopping state.
Get-CIMInstance -Class win32_service | Where-Object {$_.state -eq 'stop pending'}
Or in the Starting state:
Get-CIMInstance -Class win32_service | Where-Object {$_.state -eq 'start pending'}
Use the following PowerShell script to terminate all stuck service processes on Windows. The Stop-Process -Force
cmdlet is used to forcefully stop a process.
$Services = Get-CimInstance -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"
}
Analyze Wait Chains of a Stuck Service Using ResMon
You can detect the process that caused the service to hang and then kill it using the resmon.exe
(Resource Monitor) tool.
- In the Resource Monitor window, go to the CPU tab and find the hung service process.
- From the context menu, select Analyze Wait Chain.
- In the new window, you will most likely see that your process is waiting for another process to finish. Stop this 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.
Killing a Hung System Service Using Process Explorer
Some processes running under the SYSTEM account cannot be terminated, even by a local administrator (an “Access Denied” error appears when trying to kill a process). To stop such a service, you must first grant the local Administrators group the necessary permissions for the service process and then terminate it. This requires two tools: psexec.exe and ProcessExplorer (both are available on the Microsoft website).
- To start the ProcessExplorer with the system privileges (runas SYSTEM), use the command:
PSExec -s -i ProcExp.exe
- In the Process Explorer, find the stuck service process and open its properties.
- Go to the Services tab, find your service, and click the Permissions button.
- Grant the Administrators group Full Control rights in the service permissions. Save the changes;
- Now, try to stop the service process.Permissions for the service are only granted temporarily, until the service is restarted. To grant permanent permissions on a service, follow the article “Set permissions on a Windows service“.
The timeout that the Service Control Manager should wait for a service to start or stop can be changed by using the ServicesPipeTimeout registry parameter. If the service doesn’t start within the specified timeout, Windows will log an error to the Event Viewer. (Event ID: 7000, 7009, 7011, a timeout was reached 30000 milliseconds). For example, you can increase this timeout to 60 seconds:
reg add HKLM\SYSTEM\CurrentControlSet\Control /v ServicesPipeTimeout /t REG_SZ /d 600000 /f
This can be useful for stopping (starting) heavy services that cannot quickly terminate their running processes and close open files (for example, MS SQL Server).
5 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.
Amazingly well written and “filter” taskkill alternative for automating the task and the Powershell script are a must! Thanks for sharing and documenting.
what about service with pid 0?
Deep insight yet concise. Rare to find for Windows. Please keep going