Thursday, December 2, 2010

Adding CMD Batch files as a service

Adding batch files as a service is a little bit of a kludge, you are much better off converting your batch file to a powershell file. If you need to do it, then here is how.

First create the service using the SC command.

SC Create "MyCoolService" BinPath= "c:\program files\my cool service\mycoolservice.bat"

*Note the space after the '='

The go into the registry and locate the service you created in:


Here's the kludgy bit, you cannot spawn a batch file from a service so you have to run CMD.EXE and have that run another CMD.EXE which will continue after the service fails to start. So change the 'ImagePath' key to:

cmd /c cmd /c c:\mycoolservice.bat

When you try and run the service it will look like it fails, but it spawns your batch file anyway!


No comments:

Post a Comment