NSSM - the Non-Sucking Service Manager
nssm functions very much like srvany. When started by the system service manager, it looks in the registry for the key HKLM\System\CurrentControlSet\Services\servicename\Parameters and tries to start the program listed in Application, starting in the directory listed in AppDirectory and passing the option flags listed in AppParameters. The observant reader will notice that these values are the same as those which srvany reads, which means that nssm can be used as a direct replacement.
nssm's behaviour in regards to these registry settings changed in version 2.8. In previous versions nssm would only read the registry once, when the service was started. From version 2.8 onwards the registry is queried each time the monitored application is restarted. You no longer have to restart nssm itself after making changes to the registry.
nssm can be configured to take one of four actions when the application exits, and may even be configured to take different actions based on the application exit code. The possible actions are:
Restart - nssm will attempt to restart the application.
Prior to version 2.2 nssm always did this and it is now the default behaviour if you do not explicitly configure it as described below. Upgrading to a newer version of nssm will not change your service's behaviour.
Ignore - nssm will not attempt to restart the application. The Windows service manager will see your service as still running. This allows you to create a service which runs once at system startup and be sure that it completed successfully by checking that your service is in the running state.
This is srvany's default behaviour, though it probably isn't supposed to be and often isn't what you want, except in the use case described above.
Exit - nssm will exit. The Windows service manager will see your service as stopped. You can configure it to take an action on failure using standard operating system tools.
Suicide - nssm will exit uncleanly, without marking the service as stopped. On Windows versions prior to Vista this is the only way to ensure that service recovery actions are taken, as Exit will not work on older operating systems.
Note that nssm will not suicide if the application exited with code exit code 0, unless you explicitly add an AppExit entry for 0. This is to prevent the service manager from taking failure recovery actions after a graceful application exit.
See the usage notes for instructions on setting one of these actions for your service.
nssm can redirect the monitored application's I/O to any destination
capable of being opened with the
CreateFile() system function,
enabling you to capture status messages logged by the application, redirect input
from named pipes, access serial ports and do other esoteric things. The
usage notes have more details.
For details on how nssm runs the service and handles application failure, see the source code included in the download and check the flmonitor documentation. nssm is basically an abstraction of flmonitor.
Version 2.22 is the single biggest update to nssm since its initial release. Major new features include:
nssm now has a fully functional GUI.
With some minor exceptions which most users will never see or care about, everything nssm can do with command line arguments can also be done through its GUI.
nssm options can now be set using the command line.
Service parameters can be set without using the registry or the new GUI. As a result it is now easier to install and configure a service from a script.
nssm can now manage native services.
Parameters of most system services, such as the start type or log on user, can be managed with the command line or GUI.
nssm can start, stop and query the status of any service.
nssm can now rotate output files from the monitored application.
Logs can be rotated when they reach a configurable size while the application is running. Existing logs can also be rotated prior to starting the application.
nssm can now set the monitored application's priority class and CPU affinity.
nssm now handles console applications which try to read from stdin.
Previously such applications might exit immediately after starting because they considered end of input to mean the user wanted them to exit.
nssm is now UAC aware.
nssm will prompt for administrator credentials if you are a member of the Administrators group and launch from an unelevated command prompt.
Be aware, however, that nssm's output will be hidden if it elevates itself. This is unavoidable.
nssm is now a Unicode application.