Windows Service In Task Scheduler - Service cannot be started. The service process could not connect to the service controller

18,504

Solution 1

OK, that won't work. You can't run your service's exe directly like that from the Task Scheduler. You should use the "Net start" command to start the service.

Be sure to check the "Run with highest privileges box" in your scheduled task to avoid UAC if you are on Windows Vista or later.

Solution 2

My answer didn't format properly in the comments so I wanted to let everyone know in the event that they came across this. Basically, I just created a .bat file and then within that .bat file, I put the following two lines:

NET START MyServiceName
NET STOP MyServiceName

The NET STOP command is synchronous and will wait for the service to complete before it stops the service.

Thanks for the help!

Share:
18,504
vcuankit
Author by

vcuankit

Updated on June 04, 2022

Comments

  • vcuankit
    vcuankit almost 2 years

    I have a simple Windows Service project. I have followed instructions located at http://msdn.microsoft.com/en-us/library/zt39148a.aspx including adding custom actions.

    When run my build in Release mode for the setup project. I run the .msi onto the server I would like for the service to run on. When I open the Services Manager, the service appears. I can even manually start the service and it runs exactly as I need it to.

    However, I would like for this service to run every 5 minutes, so I set up a task in Task Scheduler and point the .exe of my windows service to the task. However, when the task scheduler runs my windows service, I get the following error:

    Service cannot be started. The service process could not connect to the service controller

    I've done a lot of research on this but haven't come up with anything. Does anyone have any ideas on what might be causing this?

  • vcuankit
    vcuankit almost 12 years
    Thank you for your response, CoreTech. Can you please elaborate a bit? Where should I put the NET START command in the task scheduler? Or should I simply start the service, and if I just start the service, then what should I place in the Actions tab?
  • CoreTech
    CoreTech almost 12 years
    On the Actions tab, add a new action to "Start a program" and enter "net start [your-service-name]" in the "Program/script" field.
  • vcuankit
    vcuankit almost 12 years
    When I do that, it gives me a warning asking if I'm using parameters. I click NO to that and try to run it. The Last Run Result says "System cannot find the file specified".
  • CoreTech
    CoreTech almost 12 years
    Try placing the net command in a batch file and specifying the batch file to run on the Action tab.
  • Andy
    Andy almost 10 years
    Windows services are normally designed to run all the time. If you want to run something every 5 minutes then either write a plain old console application and use task scheduler to run it every 5 minutes, or write a service that runs all the time and uses a timer or sleep statement to wake up every 5 minutes. starting a service every 5 minutes to perform a specific task and then stopping it again isn't really a good design