Windows service stopping automatically

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.

If within 30 seconds after trying to stop the service, it doesn’t stop, Windows displays this message:

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

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

  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;
  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.
Читайте также:  Сколько окон можно открыть windows

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;
  4. Grant the Full Control right in the service permissions for the Administrators group. Save the changes;
  5. Now try to stop the service process.

C# Windows Service — Started and then Stopped Automatically

I am creating this windows service by following the instructions at MSDN Walkthrough: Creating a Windows Service and after successful installation, I go to Services.msc to Start the Windows service and before it finishes starting up I get the following message:

The EIWindowsService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.

I know the Windows Service starts ok because there is an entry to the log file stating that the service started. I did some research before posting on here and the answer from Some Services Stop Automatically states that the problem could either be that the OnStart method is throwing an error, or that the OnStart is not kicking off a thread. So I modified my code so that the only thing within the OnStart is the starting of two timers and the log entry therefore needing no exception handling. I also added a thread to «jump» to another method.

I tried the windows service again and I know that it «moved» to the new method that the thread pointed to because I had a log entry in there that threw aFormatException error due to some conversion I was doing. I commented out the conversion and the windows service still just began to start up and then stopped automatically.

Further research indicated to me that I might need a loop to keep the processing within the method, so I took information from C — Windows Service the service on and set up an infinite while loop. I also found that there might be Garbage Collection going on and established a KeepAlive statement for the timers as suggested in Examples section of MSDN Timer Class. Still the same issues.

At this point I feel I’ve exhaused all the research I can do so it would be appropriate to post my question here. All my code is below and I will note that before I performed any change I uninstalled the Windows Service, removed the Setup Project, and deleted the installers from the C# code. I then made changes and started back over with the instructions in the Walkthrough starting at the point where it instructs how to setup the installers. I did this each time because I found that if I made changes and did not uninstall the Windows Service, remove the Setup Project, and delete the installers, then my changes would not take effect on the currently installed windows service.

Any assistance you can give would be most appreciated. I will be here for another 15min and then I will check this first thing tomorrow.

Windows service Started and stopped automatically, exception handling issue

I have developed a 32 bit service, I am running it in Windows 7 Home Premium x64. Problem is when I start it, windows gives me the following message

The WLConsumer service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.

I found the following message in the event log

Service cannot be started. System.ArgumentException: Log WLConsumer has already been registered as a source on the local computer. at System.Diagnostics.EventLogInternal.CreateEventSource(EventSourceCreationData sourceData) at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName) at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) at WeblogicConsumerService.WeblogicConsumer.winEventlogMe(String logTxt, String logSrc, Char entryType) in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 136 at WeblogicConsumerService.WeblogicConsumer.OnStart(String[] args) in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 63 at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

This is my codeblock in the OnStart() method

winEventLogMe is the method I am calling for logging.

When I comment out the calls to winEventLogMe() method in the OnStart() method, the service starts without an error. So obviously something is wrong with the winEventLogMe() method. Can someone please help me figure out whats the problem as I am totally clueless on how to solve this issue now.

thanx in advance 🙂

@nick_w I have edited my code as you suggested, the service started succesfully. But on Stopping it I got the following message:

Failed to stop service. System.ArgumentException: The source ‘WLConsumer2012’ is not registered in log ‘ServiceStop’. (It is registered in log ‘SeriviceStartup’.) » The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property. at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName) at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type) at WeblogicConsumerService.WeblogicConsumer.winEventlogMe(String logTxt, String logSrc, Char entryType) in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 139 at WeblogicConsumerService.WeblogicConsumer.OnStop() in C:\Program Files (x86)\CSI\WeblogicConsumerService\WeblogicConsumer.cs:line 70 at System.ServiceProcess.ServiceBase.DeferredStop()

here is the OnStop() method

These event logs are starting to confuse me a lot. I have done the same method of logging in other services and never encountered such problems. How can I be getting these errors in this service yet its not much different from all the others I have done 🙁

Windows services stops automatically [Solved/Closed]

Hello,
Hi everybody, this is kumar. I have problem in windows services. It stops all services automatically then I have to restart manually.. If u have any idea about stop issue and tell me how to start all services automatically?

Thanks in advance..

19 replies

We also have encountered the same problem here in our Windows Server 2003. For the meantime we have temporary solutions by setting the Recovery to «Restart the Service». By doing this:

1. Go to Administrative Tools — Services
2. Right Click «Computer Browser» then Properties
3. Click on the Recovery tab, set the following:
First Failure = Restart the the Service
Second Failure = Restart the the Service
Subsequent Failures = Restart the the Service
Reset Fail count After = 120
Restart Service after = 0
4. Click Ok

Repeat from procedure number 2 to the Services stopped.

Hope this helps.

Bong
Email Id removed for security

A few words of thanks would be greatly appreciated. Add comment

2942 users have said thank you to us this month

I see errors like this happening when there is some driver problem with the NIC.

Go to Start/Run, and type DEVMGMT.MSC , highlight the network card device, Action menu, «Uninstall», then restart Windows, to find
the device drivers
again automatically.

This is kishore, I have problem in windows services. It stops all services automatically then I have to restart manually.Results error in network connection.

My name is Yugen Pillay, I’m from South Africa.
I am also having the problem where the Computer Browser is disabling itself.
Can you please help me.

Thank you for your time.

Really weird one.
Small network, workstations all XP SP2 and updates.
MACfee Anti Virus Software, Corp Edition all up to date.
One of the machines on the network will simply just stop some services
on its own accord. Normally happens right after logging off, but also
happens while machine is logged on.

Services stopped are:
· Automatic Updates
· Computer Browser
· Cryptographic Services
· DHCP Client
· Distributed Link Tracking Client
· Error Reporting Service
· Help and Support
· Logical Disk Manager
· Secondary Logon
· Security Center
· Server
· System Event Notification
· System Restore Service
· Task Scheduler
· Themes
· Windows Audio
· Windows Firewall/Internet Connection Sharing (ICS)
· Windows Management Instrumentation
· Windows Time
· Wireless Zero Configuration
· Workstation

Users logging on and off do not have admin rights on the machine, so
presumably the services are not stopped using the user rights.

Already reloaded SP2, full virus scan, spyware / addware scan, just no
success.
From what I could see, it does not happen if the network cable is
unplugged.

Hi Hamster
Have you got any solution for this Problem, I have windows 2003 Server with SP2 and I am also experiencing the same Problem in my Network.

I am using this Server As DHCP and Print Server in my Network , please let me know if have any updated solution on this.

Regards
Naresh Rana

Have you found out what is causing this and how to fix it? I have a friend with this same problem you described here.

did you find the solution for your problem?

because I have the same in our network and I have the same antivirus and the same services stopped, I tryed to install symantec corporate edition and updated but nothing changed, I fraid this is new virus because I have this problem in the same time you have.

please if you have any solution send it to my email:

Email Id’s removed for security

· Automatic Updates
· Computer Browser
· Cryptographic Services
· DHCP Client
· Distributed Link Tracking Client
· Error Reporting Service
· Help and Support
· Logical Disk Manager
· Secondary Logon
· Security Center
· Server
· System Event Notification
· System Restore Service
· Task Scheduler
· Themes
· Windows Audio
· Windows Firewall/Internet Connection Sharing (ICS)
· Windows Management Instrumentation
· Windows Time
· Wireless Zero Configuration
· Workstation

Читайте также:  Как удалить файлы драйвера windows 10
Оцените статью