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

windows-services

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?

Best Answer

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.