Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / Windows Server 2012 R2 / Killing a Windows Service that Hangs on Stopping or Not Responding

April 8, 2019 Windows 10Windows Server 2008 R2Windows Server 2012 R2Windows Server 2016

Killing a Windows Service that Hangs on Stopping or Not Responding

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.

Windows Service hang on "Stopping"

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.

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.

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

Contents:
  • How to Terminate a Hung Windows Service Process Using TaskKill?
  • PowerShell: Stop Windows Service with Stopping Status
  • Identify a Hang Process Using Resmon
  • Process Explorer: Killing a Hung Process Running in SYSTEM Context

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

Quite often this problem happens with the Windows Modules Installer service at server reboot, especially after installing updates on Windows Server 2012 R2 / 2008 R2.
Important. Be attentive. A forced shutdown 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 816.
To force stop a hung process with the PID 816, run the command:

taskkill /PID 816 /F

kill service process by pid

SUCCESS: The process with PID 816 has been terminated.

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

list of services with "Stop pending" status

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

Powershell Stop Process

Identify a Hang Process Using Resmon

You can detect the process that caused the service freeze using the resmon (Resource Monitor).

  1. In the Resource Monitor window, go to the CPU tab and locate 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.

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

  1. To run ProcessExplorer with the system privileges (runas SYSTEM), run the utility in this way: 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, prior to its restart. To grant permanent permissions on service follow the article Set permissions on a Windows service.

2 comments
3
Facebook Twitter Google + Pinterest
previous post
Managing Local Users and Groups with PowerShell
next post
Configuring an FTP Server with User Isolation on Windows Server 2016 / 2012 R2

Related Reading

How to Sign a PowerShell Script (PS1) with...

February 25, 2021

How to Shadow (Remote Control) a User’s RDP...

February 22, 2021

Configuring PowerShell Script Execution Policy

February 18, 2021

Configuring Proxy Settings on Windows Using Group Policy...

February 17, 2021

Updating Group Policy Settings on Windows Domain Computers

February 16, 2021

2 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

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • How to Sign a PowerShell Script (PS1) with a Code Signing Certificate?

    February 25, 2021
  • Change the Default Port Number (TCP/1433) for a MS SQL Server Instance

    February 24, 2021
  • How to Shadow (Remote Control) a User’s RDP session on RDS Windows Server 2016/2019?

    February 22, 2021
  • Configuring PowerShell Script Execution Policy

    February 18, 2021
  • Configuring Proxy Settings on Windows Using Group Policy Preferences

    February 17, 2021
  • Updating Group Policy Settings on Windows Domain Computers

    February 16, 2021
  • Managing Administrative Shares (Admin$, IPC$, C$, D$) in Windows 10

    February 11, 2021
  • Packet Monitor (PktMon) – Built-in Packet Sniffer in Windows 10

    February 10, 2021
  • Fixing “Winload.efi is Missing or Contains Errors” in Windows 10

    February 5, 2021
  • How to Move (Clone) Windows to a New Hard Drive (HDD/SSD)?

    February 4, 2021

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • How to Allow Multiple RDP Sessions in Windows 10?
  • How to Repair EFI/GPT Bootloader on Windows 10?
  • How to Restore Deleted EFI System Partition in Windows 10?
  • Network Computers are not Showing Up in Windows 10
  • Booting Windows 7 / 10 from GPT Disk on BIOS (non-UEFI) systems
  • How to Run Program without Admin Privileges and to Bypass UAC Prompt?
  • Removable USB Flash Drive as Local HDD in Windows 10 / 7
Footer Logo

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


Back To Top