Question: 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?

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](http://www.coretechnologies.com/WindowsServices/FAQ.html#StartStopFromCommandLine) 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.
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!