Im using Windows XP and i want to run a particular bat file as a windows service.Is there any way to do that ?
Please Help Thank You
Running a batch file as a service is a fairly odd application, and there's a reasonable likelihood that you're going to have problems.
Assuming that you have a batch file that runs in a continuous loop, I suppose you could run the batch file as a service. Like Warner says, you're going to want have to use a "service manager" wrapper (like the SRVANY that Warner mentions, or the free Non-Sucking Service Manager (NSSM)) program.
Warner's description of creating a service w/ SC, referencing SRVANY, is all correct. For some technical background: A real service program responds to control functions from the service control manager (SCM). These control functions allow the service control manager (and, thus, the Services management console snap-in, etc) to stop, start, pause, etc, the service program. The basic flow is:
SCM --(invokes)--> wrapper (SRVANY, NSSM) --(invokes)--> your program
If your batch file spawns additional processes when you stop the service (which is really stopping the wrapper program) you'll find that programs spawned by your batch file won't be killed and will hang around indefinitely.
SRVANY also doesn't monitor your batch file (running in CMD.EXE), and if your program "dies" the "service" will remain listed as "started". (NSSM can monitor the child CMD.EXE and restart it, but NSSM still suffers from the problem of not killing child processes of the batch file on service stop).
NSSM has a GUI to help create the service and associate it with your program. You might like that if you're not a command-line and registry-manipulation kind of person.
All-in-all, running non-service programs in wrappers isn't a recommended practice. I do it in some production environments, but I'm always wary of it and try to test such applications a lot before I consider it "working".
You can use the
Now, the service created is using Srvany.exe, which is part of the Windows Resource Kit. This enables you to define a service with your software that otherwise would not support it.
After that, you will need to use RegEdit to create a "Parameters" key for your service under
Microsoft has instructions for this as well using a different method to create the service initially.