Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceController seems to be unable to stop a service

I'm trying to stop a Windows service on a local machine (the service is Topshelf.Host, if that matters) with this code:

serviceController.Stop(); serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeout); 

timeout is set to 1 hour, but service never actually gets stopped. Strange thing with it is that from within Services MMC snap-in I see it in "Stopping" state first, but after a while it reverts back to "Started". However, when I try to stop it manually, an error occurs:

Windows could not stop the Topshelf.Host service on Local Computer. Error 1061: The service cannot accept control messages at this time. 

Am I missing something here?

like image 415
Anton Gogolev Avatar asked Jun 09 '11 12:06

Anton Gogolev


People also ask

How do I fix error 1061?

Kill the svchost.exe netsvcs process. Then start the Application Information service from Services. Check all automatic services as a few may have stopped and start them again. This should resolve the issue.


2 Answers

I know I am quite late to answer this but I faced a similar issue , i.e., the error: "The service cannot accept control messages at this time." and would like to add this as a reference for others.

You can try killing this service using powershell (run powershell as administrator):

#Get the PID of the required service with the help of the service name, say, service name. $ServicePID = (get-wmiobject win32_service | where { $_.name -eq 'service name'}).processID   #Now with this PID, you can kill the service taskkill /f /pid $ServicePID 
like image 94
Rishi Avatar answered Sep 18 '22 07:09

Rishi


Either your service is busy processing some big operation or is in transition to change the state. hence is not able to accept anymore input...just think of it as taking more than it can chew...

if you are sure that you haven't fed anything big to it, just go to task manager and kill the process for this service or restart your machine.

like image 31
Niranjan Malviya Avatar answered Sep 19 '22 07:09

Niranjan Malviya