by softlion
28. December 2009 11:32
When you want to run a program as a service on Windows, the program have to be created specifically for this by implementing the Windows service interface.
When you don’t want to waste your time, or for any reason you could think of, there is a solution to run an exe as service. You can use the well known solution combining instsrv+srvany which works only on 32 bit windows, or NSSM which now works both on Win32 and x64.
Usage: type NSSM without argument:
Practical usage
For use in a single install.bat batch file without any user interaction:
rem stop and uninstall the service. Useful if the .bat is run twice.
sc stop YourServiceName
nssm remove YourServiceName confirm
rem install and configure the service
nssm install YourServiceName “%CD%\Your Service Name.exe”
sc config YourServiceName start= auto depend= tcpip/LmHosts/Eventlog
sc description YourServiceName "Description of your service for display in service manager"
sc start YourServiceName
In .bat files, %CD% is replaced with the current path.
Our service is configured to start at boot (start= auto), so we need to specify which service should be up before this service can start (depend= …)
Replace nssm by nssm-x64 if you run on 64 bits Windows.
Download
References
Original NSSM (2006)
___