How to shutdown a hung service in Windows. How to forcibly terminate a hung service? Analyzing hung processes with Resmon

How to shutdown a hung service in Windows. How to forcibly terminate a hung service? Analyzing hung processes with Resmon

26.07.2021

If any Windows service fails, you must either restart the service or reboot the system. Restarting your computer is inconvenient because it takes time and closes all windows. If you cannot stop the service through the Control Panel, you can restart the Windows service from command line.

There are 4 ways to open Windows service settings:

  1. Click Win + R, in the window Execute to introduce services.msc and press Enter. The Service Manager will open.
  2. Click Start, in the search enter Services, open settings.
  3. Open Control Panel -> System and Security -> Administrative Tools -> Services.
  4. Press RMB on the button Start or keys Win + X... Go to Computer Management -> Services and Applications -> Services.

Fortunately, from version to Windows versions this section of the settings has hardly changed. On Windows 7, Vista, 8, and 10, Services will look almost the same.

Restarting via Control Panel

The possibilities of the standard settings in the Control Panel are enough to stop and start system services. There is a possibility - this will slightly increase the performance of the device.

Stopping and restarting Windows services:

  1. Open a window in any way Services, find the one you need.
  2. Right-click on the desired service and select Restart.
  3. If the button Restart inactive - press Properties.
  4. Click Stop, wait for the service to stop.
  5. Press the button Run.

If the service hangs or does not stop - open the task manager (Ctrl + Alt + Del) and terminate all processes associated with the problematic service.

Restarting via Command Line

If the Control Panel is not doing its job, you can disable or restart the service through the Command Line (cmd.exe). Command line must be run as administrator.

To manage services, there are 4 commands that duplicate the functionality of the Control Panel:

  • net stopservice- Stop the selected service.
  • net startservice- Run.
  • net pauseservice- Suspend service.
  • net continueservice- Resume service.

To work with a service, you need to know its name. For example, launch service Windows Audio will be executed on command net start audiosrv... Here audiosrv is the system name of the service.

To find it out, you need to go to the properties. The required line will be at the very top - "Service Name". You can list the names of all active services directly in the Command Prompt by entering sc query type = service.

Through the console, you can not only restart the service, but also change its startup type with the command sc config *SERVICE* start =* START_TYPE *.

Available launch types:

  • auto- Automatically.
  • demand- Manually (upon request).
  • delayed-auto- Delayed start.

For example, the command sc config audiosrv start = auto will translate the service Windows Audio to startup type Automatically.

For the sake of completeness, another way to restart should be mentioned - through the Task Manager. To do this, you need to press the key combination Ctrl + Alt + Del(or Ctrl-Shift-Esc), select Task Manager and go to the tab Services... By right-clicking on any service, a context menu appears, from where you can stop, start, and restart.

How do I end the process of a Windows service stuck in stopping status? I think most Windows administrators have encountered situations when, when trying to stop (restart) a service from the graphical interface of the service management console (Services.msc), the service hangs tightly and hangs in the status Stopping... After that, you cannot stop the service in the console, because the service action buttons become unavailable. The easiest way is to reboot the server, but this is not always acceptable. Consider an alternative way to allow forcibly terminate a hung service or a process without the need for a reboot.

If within 30 seconds after trying to stop the service, it does not stop, Windows displays the message:

Failed to stop the xxxxxxx Windows service on the local computer.
Error 1053. The service did not respond to the request in a timely manner.

Windows Could not stop the xxxxxx service on Local Computer
Error 1053: The service did not respond in a timely fashion.

When you try to stop such a service with the command: net stop wuauserv, a message appears:

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

Terminating a hung service with TaskKill

The easiest way to terminate a frozen service is to use the utility taskkill. First of all, you need to determine PID(process id) of our service. Take the service Windows Update, her system name wuauserv(the name can be found in the properties of the service in the services.msc console).

This problem happens quite often, especially after installing updates on Windows Server 2012 R2 / 2008 R2.

Important... Be attentive. Forcibly resigning a critical Windows service process can lead to BSODs or system reboots.

On the command line with administrator rights (this is important, otherwise there will be an access denied error):
sc queryex wuauserv

In this case, the PID of the process is 816.

To force quit a hung process with PID 816:

taskkill / PID 816 / F

SUCCESS: The process with PID 816 has been terminated.

This command will forcibly terminate the service process. In the future, you can return to the service management console and manually start the service (or completely, if you do not need it).

A headshot of a hung service can be performed more elegantly without manually detecting the PID of the process. The taskkill utility has a / FI option to use a filter to select the required services or processes. You can stop a specific service with the command:

TASKKILL / F / FI "SERVICES eq wuauserv"

Or you can not specify the name, services at all, ending all services in a hung state using the command:

taskkill / F / FI “status eq not responding”

After that, the service that is stuck in the Stopping status should stop.

Force termination of a hung service from PowerShell

You can also use PowerShell to force stop the service. Using the following command, you can get a list of services that are in the Stopping state:

Get-WmiObject -Class win32_service | Where-Object ($ _. State -eq "stop pending")

The cmdlet will help you complete the process for all found services. Stop-Process... Combining both operations into a loop, we get a script that automatically terminates all processes of suspended services in the system:

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

Analyzing hung processes with Resmon

You can identify the process causing the service to hang by using the resmon resource monitor.


Process Explorer: Terminating a hung process from under SYSTEM

Some processes launched under SYSTEM cannot be terminated even by the local server administrator. The fact is that it simply may not have rights to some processes or services. To terminate such a process (services), you need to grant the local Administrators group rights to the service (process), and then terminate them. For this we need two utilities: psexec.exe and ProcessExplorer (available on the Microsoft website).


System administrators usually have to deal with the need to force shutdown of services, but it may well be that during some configuration, you will need to perform such an operation - ordinary user... You open the service management console, find a service that needs to be stopped or restarted, click the corresponding link in the left pane, but instead of safely stopping or restarting the service hangs in the status "Stop".

And no longer reacts to anything. And later 30 seconds you get the following message:

Failed to stop NAMESERVIS Windows service on local computer.
Error 1053... The service did not respond to the request in a timely manner.

The first thing that comes to mind is to reboot the computer. This usually helps, but it may well be that a second attempt to stop the service will be unsuccessful and lead to its re-freezing, or a restart is impossible for some reason. In this case, there is nothing left but to terminate its work in a forced mode.

To begin with, you can try using the most common task manager... Open the dispatcher, find the unresponsive service, right-click on it and select in context menu option.

This action will take you to the service process, which can then be terminate in forced mode .

You can also shut down the service through the command line running on behalf of the administrator using the standard utility taskkill... The command looks like this:

taskkill / PID Service no. / F

Peep PID can be in the task manager tab "Services" or by running the sc queryex name command, where name- systemic (latin) service name.

The result of the command taskkill with PID and parameter F there should be a message "Process, with identifier completed successfully " .

I think that most users have encountered such a problem as freezing of services in Windows, moreover, an attempt to force termination of such a service was unsuccessful, and it weighs in the mode "Stopping"... It is also not possible to restart or forcibly terminate the service from the graphical interface, and restarting the server itself, in our case the computer, may not always be acceptable.

Now we will consider a method that will help you to forcibly end the process that has frozen, while the device itself does not need to be restarted.

How to forcibly terminate a hung service?

So, as soon as 30 seconds have passed and you can see that the service has not stopped, then Windows will display the following message:

You can quickly and effortlessly terminate a frozen process using a utility. Before that, you will need to define PID process (service). As an example, we will use a service, the system name of the process is wuauserv.

Attention! If you complete an important process, then it can lead to a system reboot or BSOD (screen of death).

Now we open the command line with administrator rights, if you do not do this, an error may occur. Enter the following into the command line:


A message appears that the Windows Update service has ended. You can then return to service management and start the process there again, or delete it altogether if you do not use it.

There is one more method of forcibly terminating the process, while you do not need to find out the PID. The already familiar utility will help us in this matter. We run it as administrator.

The following command will help us identify services that are in the stopping state:

Get-WmiObject -Class win32_service | Where-Object ($ _. State -eq ‘stop pending’)


Now we need to complete the process for the services we found, this will help us with this. With the help of the following script, all services that hang on the system will be terminated:

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


That's all, today we were able to complete processes that we could not complete, for example, using the device manager or from the graphical shell.

Manually, but automatically.

When tincture operating system, very often you have to perform the same actions to disable the same services. This annoyed me and I could not find a way to automate it. But now I've created a file that automatically disables the services I don't need. If you also have such a need, then read below how this can be done!)

In Windows 7, 8, 10, to work with services, you need:

  1. Open start
  2. Right-click on the computer and select control
  3. Go service and control
  4. Services. A list of services appears.

How do I manually stop the service?

  1. In order to stop the service, right-click and select the property
  2. Click stop

How do I manually start the service?

  1. In order to start the service, right-click and select the property
  2. Click run

How do I manually disable a service?

  1. In order to disable the service, right-click and select the property
  2. Click stop (you can do without this, but then you will have to restart the computer so that it is disabled)
  3. We select the startup type disabled (often people are interested in how to stop the service windows updates, just in this way you need)

When I wrote an article about which services can be disabled, I was asked to write a script that automatically disabled the necessary services automatically. And I found a solution recently. To do this, you need to stop the service from the command line. But again, on the one hand, it looks difficult, but at the end of the article I will teach you how to do it simply.

How to automatically stop, start, disable a service?

Download my template first. These are services that I usually turn off as soon as I put them on.

Now look at the commands we need (commands are taken without quotes):

  1. "Net stop service_name" - This command stops the service
  2. "Net start service_name" - this command starts a stopped service
  3. Sc config service_name start = value - This command changes the startup type of the service.

The "value" field can be of 3 types:

  • auto (automatically);
  • demand (on demand, manually);
  • delayed-auto (delayed start);

The service_name field can be recognized as follows:

  1. Right-click on the required service and select the property
  2. The service name is the name we need.

Now click on the downloaded file (Disable unnecessary services.bat) above with the right mouse button and click change.

For me, the first line stops the service, and the second disables it, and so it is repeated 4 times with different services. There is a pause at the end so that you can see what has been done.

  1. Those. looking for the name of the service
  2. We write the command to stop or start
  3. We write a command of the type of launch
  4. Save the file
  5. We just click on it twice with the mouse button and that's it. The script will automatically execute your commands.

Thus, if you often disconnect or stop something, you just need this method to save your time!

© 2021 hecc.ru - Computer technology news