Installing a command line executable as a service?
Hi all, I have a executable file which works perfectly when launched from the command line of my Windows 2008 Server, and I am wanting to configure it as a Windows service so I don't have to be logged in for it to run. Using the sc Windows command I installed this; $ sc.exe create MyApp start= auto binpath= "c:\Services\MyApp\MyApp.exe --logfile=c:\Services\MyApp\Log\MyApp.log" DisplayName= MyApp I get a message that the service has been installed properly, and when I start the service I can see that the MyApp.exe process is launched and works. However, for some reason Windows Service Control Manager doesn't seem to think that the service has started correctly and gives me a " StartService FAILED 1053" error and terminates the process. I've also tried using the srvany.exe utility to install the executable as a service with the same result. After reading around a bit I found this blog which explains that when starting a service the Service Control Manager (SCM) waits a while for the newly launched service establishes a communication channel using the RegisterServiceCtrlHandler API. If this communication channel is not forthcoming, then SCM terminates the service process. This blog also suggests using a "feature" where you can use cmd.exe as the service to launch your process. The result is that the service fails and the cmd.exe window is terminated, however the process you spawn via cmd.exe stays alive. I tested this and it works, however it is a pretty darn ugly work around and you also lose any control over your process using SCM. Installing command line applications as services in Windows is nothing new (has been available since at least Windows 2000 with the sc.exe command), and I was just wondering if I was missing anything here? If an application is never built with the intention of being run as a service, then I'd assume it is unlikely that any of the SCM related API's have been accommodated for. How in these instances then are you able to install a simple application as a service without SCM terminating it everytime?
March 16th, 2010 3:18pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics