Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows Server 2019 / Kill a Windows Service That Stucks on Stopping or Starting

August 5, 2021 PowerShellWindows 10Windows Server 2019

Kill a Windows Service That Stucks on Stopping or Starting

How to manually kill a Windows service process that is stack at “Stopping” or “Starting” state? Most Windows administrators have faced a problem when they try to start/stop/restart a service, but it gets stuck with the Stopping (or Starting) 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 (grayed out). The easiest way is to restart Windows, but it is not always acceptable. Let’s take a look at alternative ways, which allows to forcefully kill a stuck Windows service or process without system reboot.

windows service stopping, starting, not responding

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.
The timeout that the Service Control Manager waits 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 sends an error to the Event Viewer (Event ID: 7000, 7009, 7011, a timeout was reached 30000 milliseconds). You can increase this timeout to 60 seconds, for example:

reg add HKLM\SYSTEM\CurrentControlSet\Control /v ServicesPipeTimeout /t REG_SZ /d 600000 /f

This is useful when starting/stopping heavy services that do not have enough time to properly terminate all processes and close the files (for example, MS SQL Server).

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 later.

The service is starting or stopping. Please try again letter.

or:

Windows could not stop the Service on Local Computer.
[SC] ControlService Error 1061: The service cannot accept control messages at this time.

Contents:
  • How to Force Kill a Stuck Windows Service Using TaskKill?
  • Force Stop a Stuck Windows Service with PowerShell
  • Analyzing the Wait Chains on Hung Services Using ResMon
  • Killing a Hung Service Using Process Explorer

How to Force Kill a Stuck Windows Service Using TaskKill?

The easiest way to stop a stuck service is to use the built-in taskkill command-line tool. First of all, you need to find the PID (process identifier) of the service. As an example, let’s take the Windows Update service. Its system name is wuauserv (you can check the name in the service properties in the services.msc console).

It is very common to see the Windows Modules Installer service hang when the server is restarted, especially after installing updates on Windows Server 2012 R2 and 2016.
Important. Be attentive. Forced termination of critical Windows services can result in BSOD or an unexpected system restart.

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 9186.
To force kill a stuck process with the PID 9186, run the command:

taskkill /PID 9168 /F

stopping stuck windows service in cmd using taskkill

SUCCESS: The process with PID 9168 has been terminated.

This command will forcibly terminate the service process. Now you can start the service with the sc start servicename command or through the service management console

You can stop a hung service more elegantly without manually checking the PID of the service process. The taskkill tool has the /FI option, which allows you to use a filter to select the necessary services or processes. You can kill 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 that, the service that is stack in the Stopping status should stop.

You can also use the taskkill utility to force stop the hang services on a remote computer:

taskkill /S mun-fs01 /F /FI "SERVICES eq wuauserv"

Force Stop a Stuck Windows Service with PowerShell

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'}

Or in the Starting state:

Get-WmiObject -Class win32_service | Where-Object {$_.state -eq 'start pending'}

list of services with "Stop pending" status

The Stop-Process cmdlet allows terminating the processes of all found services. The following PowerShell script will terminate all stuck service processes on Windows:

$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"
}

powershell script to kill stuck service process

You must use the Get-CimInstance instead of the Get-WmiObject cmdlet in the new PowerShell Core 6.x/7.x. Replace the first command of the script with:

$Services = Get-CimInstance -Class win32_service | where-Object state -eq 'stop pending'

Analyzing the Wait Chains on Hung Services Using ResMon

You can detect the process that caused the service to hang using the resmon.exe (Resource Monitor).

  1. In the Resource Monitor window, go to the CPU tab and find the hung service process;
  2. Select the item Analyze Wait Chain from the context menu;Resource Monito analyze wait chain
  3. 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.

Killing a Hung Service Using Process Explorer

Even the local administrator cannot terminate some processes that run under the SYSTEM account. The fact is that the admin account simply hasn’t permissions on some processes or services. To stop such a process (service), you need to grant permissions to the service (process) to the local Administrators group and then kill them. To do this, we will need two small tools: psexec.exe and ProcessExplorer (available on the Microsoft website).

  1. To start the ProcessExplorer with the system privileges (runas SYSTEM), use the command: PSExec -s -i ProcExp.exe
  2. In the Process Explorer process list, find the stuck service process and open its properties;
  3. Go to the Services tab, find your service and click the Permissions button;proccess explorer service permissions
  4. Grant the Full Control right in the service permissions for the Administrators group. Save the changes;granting full control permissions on windows service for admin
  5. Now try to stop the service process.
    Please note, that the permission on the service is granted temporarily until it is restarted. To grant permanent permissions on service follow the article Set permissions on a Windows service.

 

5 comments
8
Facebook Twitter Google + Pinterest
previous post
How to Repair and Reinstall Microsoft Store on Windows 10 After Removal?
next post
Managing Saved Passwords Using Windows Credential Manager

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

5 comments

Jay Adams November 4, 2016 - 1:39 pm

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.

Reply
Rick Noel November 19, 2019 - 1:43 pm

Terrific information very well laid out. Thank you.

Reply
Sergio Villaseca October 17, 2021 - 3:58 pm

Amazingly well written and “filter” taskkill alternative for automating the task and the Powershell script are a must! Thanks for sharing and documenting.

Reply
jjjn October 29, 2021 - 4:15 am

what about service with pid 0?

Reply
Stefan Schletterer November 7, 2022 - 8:41 am

Deep insight yet concise. Rare to find for Windows. Please keep going

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Configuring Port Forwarding in Windows
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Adding Drivers into VMWare ESXi Installation Image
  • How to Hide Installed Programs in Windows 10 and 11
  • Configuring SFTP (SSH FTP) Server on Windows
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top