What NSSM does
NSSM is a service helper program similar to srvany and
cygrunsrv, but with the features a real service manager needs.
It can start any application as an NT service and will restart the service
if it fails for any reason.
Any application as a service
Console tools, scripts via cmd /c, Java programs, game servers, Node.js apps — if it can be launched from a command line, NSSM can run it as a service.
Automatic restart
Crashed or exited applications are restarted automatically. Throttling and configurable restart delays stop a broken application from spinning the CPU.
Graceful shutdown
On stop, NSSM tries Control-C, window messages and thread messages before falling back to TerminateProcess(). Each stage has a configurable timeout and can be disabled.
Logging & rotation
Redirect stdin/stdout/stderr to files, with millisecond-precision timestamps, online rotation by size or age, and copy-and-truncate rotation for files held open by other processes.
Environment control
Replace or extend the service environment with AppEnvironment and AppEnvironmentExtra, with full %VAR% expansion.
Priority & CPU affinity
Set the process priority class and pin the application to specific CPUs with a simple list such as 0-2,4.
Event hooks
Run your own commands before/after start, stop, exit, log rotation or power events. Hooks receive a rich set of NSSM_* environment variables describing the event.
Runs as anyone
LocalSystem, virtual accounts, or any user account. Startup type, display name, description, dependencies and service type are all settable from the CLI or the GUI.
GUI & full CLI
Install and edit services in a friendly GUI, script everything from the command line, and export any service's configuration with nssm dump.
About this fork
NSSM was originally written by Iain Patterson and released into the public domain; the original site is nssm.cc. Its last release (2.24) dates from 2017. This is a maintained continuation with the following changes, and it remains 100% compatible with the original command syntax and registry layout.
Actively maintained
Bug fixes continue: restart without rebooting, log-rotation thread stability, hook and throttle race conditions, memory safety.
Remove without reboot
nssm remove stops the service first and retries on ERROR_SERVICE_MARKED_FOR_DELETE — no more rebooting just to reinstall a service.
Security hardening
DLL loading uses LOAD_LIBRARY_SEARCH_SYSTEM32, plus fixes for buffer overflows, resource leaks and NULL-pointer crashes.
Tested
A unit test suite (catch2) and an integration test suite (Pester) run in CI on every change, covering lifecycle, parameters and crash recovery.
Legacy Windows friendly
Release binaries are built with Visual Studio 2008 and run on Windows XP and later, including 32-bit systems. Modern development uses VS2019+.
sc.exe-style alias
nssm delete works as an alias for nssm remove, matching sc.exe conventions.
HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters.
WinSW-style XML/YAML configuration files are not currently supported —
use nssm set for scripting and nssm dump to export a
service as a ready-to-run batch script (handy for backups and migration).
Quick start
All commands require an administrator command prompt. In the examples below we
install a Node.js application as a service named myapp — substitute
your own paths.
-
Install the service
The quickest way — pass everything on the command line:
nssm install myapp "C:\apps\node\node.exe" "C:\apps\myapp\server.js"
Or run
nssm install myappwithout an application path to open the GUI installer. Paths containing spaces must be quoted. -
Tune the essentials
rem Where the application starts nssm set myapp AppDirectory C:\apps\myapp rem Log stdout and stderr to files nssm set myapp AppStdout C:\logs\myapp.out.log nssm set myapp AppStderr C:\logs\myapp.err.log rem Rotate logs at 10 MB and prefix each line with a timestamp nssm set myapp AppRotateFiles 1 nssm set myapp AppRotateBytes 10485760 nssm set myapp AppTimestampLog 1 rem Show the service as "My Application" with a description nssm set myapp DisplayName "My Application" nssm set myapp Description "My web application server"
-
Start it
nssm start myapp
Check that it is running:
nssm status myapp nssm processes myapp
-
Manage it day to day
nssm restart myapp nssm stop myapp nssm list
You can also control the service with
services.mscorsc.exe— NSSM services are ordinary Windows services. -
Back it up or move it
nssm dump myapp
Prints a batch script which recreates the service. Run the output on another machine (after copying
nssm.exethere) to clone the service.nssm dump myapp myapp2showsmyapp's configuration but writes commands for a service namedmyapp2. -
Remove it
nssm remove myapp confirm
NSSM stops the service first, then deletes it. No reboot needed even if the service was running.
nssm install (no arguments) or
nssm edit myapp to configure everything — paths, logging, rotation,
environment, priority, affinity, hooks — through a dialog instead of the CLI.
Command reference
Everywhere <servicename> appears you may substitute the
service's display name as well as its key name. Run nssm with no
arguments to see built-in usage.
| Command | Syntax | Description |
|---|---|---|
install | nssm install <servicename> [<app> [<args>]] | Install a service. With an application path the service is created directly; without one, the GUI installer opens. |
remove | nssm remove <servicename> [confirm] | Stop and delete a service. Without confirm a GUI confirmation is shown. delete is an alias. |
edit | nssm edit <servicename> | Open the GUI editor for an installed service. |
get | nssm get <servicename> <parameter> | Print the current value of a parameter. |
set | nssm set <servicename> <parameter> <value> | Set a parameter. All remaining arguments are concatenated with spaces to form the value. |
reset | nssm reset <servicename> <parameter> | Restore a parameter to its default. unset is an alias. |
dump | nssm dump <servicename> [<newname>] | Print batch commands which recreate the service's configuration, properly quoted and escaped. |
start | nssm start <servicename> | Start the service. |
stop | nssm stop <servicename> | Stop the service. |
restart | nssm restart <servicename> | Stop, then start the service. |
pause | nssm pause <servicename> | Pause the service (also pauses restart attempts). |
continue | nssm continue <servicename> | Resume a paused service. |
status | nssm status <servicename> | Print the service state, e.g. SERVICE_RUNNING. Exit code 0 on success. |
statuscode | nssm statuscode <servicename> | Exit with the numeric service state, e.g. 4 for SERVICE_RUNNING. Useful in scripts. |
rotate | nssm rotate <servicename> | Trigger an on-demand log rotation (requires online rotation to be enabled). |
list | nssm list [all] | List services managed by NSSM; with all, list every service on the system. |
processes | nssm processes <servicename> | Show PID and executable path of the processes launched by a service. |
version | nssm version | Print the NSSM version and build configuration. |
Configuration reference
All settings live in the registry under
HKLM\SYSTEM\CurrentControlSet\Services\<service>\Parameters
and are managed with nssm get / nssm set /
nssm reset. Parameter names on the command line are the same as the
registry value names below.
Application
| Parameter | Type | Meaning |
|---|---|---|
Application | Path | Full path of the program to run. Relative paths are resolved against the directory NSSM was started from. |
AppParameters | String | Command-line arguments passed to the application. |
AppDirectory | Path | Working directory for the application. |
AppExit | String | Action when the application exits. See exit actions. Set per exit code via nssm set <svc> AppExit <code> <action>. |
Process control
| Parameter | Type | Meaning |
|---|---|---|
AppThrottle | REG_DWORD (ms) | If the application runs for less than this long (default 1500), the start counts as a failure and restart pauses get progressively longer, up to 4 minutes. Send a continue from services.msc to retry immediately. |
AppRestartDelay | REG_DWORD (ms) | Unconditional pause before restarting the application, even after a clean run. The longer of this and the throttle period applies. |
AppPriority | REG_DWORD | Priority class, e.g. set with nssm set <svc> AppPriority NORMAL_PRIORITY_CLASS. Values: REALTIME, HIGH, ABOVE_NORMAL, NORMAL, BELOW_NORMAL, IDLE (_PRIORITY_CLASS suffix). |
AppAffinity | REG_SZ | Comma-separated, zero-indexed CPU list with optional ranges, e.g. 0-2,4. 32-bit NSSM manages at most 32 CPUs. |
AppNoConsole | REG_DWORD | Set to 1 to suppress the console window NSSM creates by default. |
AppKillProcessTree | REG_DWORD | Set to 0 to apply stop methods only to the main process instead of the whole process tree. |
I/O redirection
| Parameter | Type | Meaning |
|---|---|---|
AppStdinAppStdoutAppStderr | Path | Files to connect to the application's stdin, stdout and stderr. Set stdout and stderr to the same path to capture both. The path must be writable by the service account. |
AppStdout/Stderr/Stdin | REG_DWORD | Fine-tune the CreateFile() call used to open each stream, e.g. AppStdoutShareMode, AppStdoutCreationDisposition, AppStdoutFlagsAndAttributes. Sensible defaults apply when omitted. |
AppTimestampLog | REG_DWORD | Set to 1 to prefix each line of redirected output with a millisecond-precision timestamp, e.g. 2016-09-06 10:17:09.451 message. |
Log rotation
| Parameter | Type | Meaning |
|---|---|---|
AppRotateFiles | REG_DWORD | Set non-zero to enable rotation. The existing file is renamed with a timestamp suffix, e.g. nssm-20131221T113939.457.log. |
AppRotateOnline | REG_DWORD | Set non-zero to enable online rotation (rotate while running and support nssm rotate). NSSM then intercepts the application's I/O, which is more complex; disabled by default. |
AppRotateSecondsAppRotateBytesAppRotateBytesHigh | REG_DWORD | Skip rotation unless the file's last write is at least this old / the file is at least this large. Combine both; AppRotateBytesHigh extends the size limit to 64 bits. |
AppRotateDelay | REG_DWORD (ms) | Pause after rotating, so log readers can notice the size change. |
AppStdoutCopyAndTruncateAppStderrCopyAndTruncate | REG_DWORD | Rotate by copying the file then truncating the original, for files held open by other processes. Uses extra disk space temporarily. |
Exit actions
NSSM reads AppExit values named after the application's exit code,
falling back to the default value. Check the Windows event log to find the exit
code. Configure per code with nssm set <svc> AppExit <code> <action>
or the default with nssm set <svc> AppExit Default <action>.
| Value | Behaviour |
|---|---|
Restart | Restart the application (default behaviour). |
Ignore | Keep the service running even though the application exited (srvany emulation — usually undesirable). |
Exit | Stop the service cleanly so Windows recovery actions can take over. |
Suicide | Simulate a crash so pre-Vista recovery actions trigger. Only honoured for exit code 0 if explicitly configured. |
Stopping the application
When a service stops, NSSM tries four methods in order, each with a default 1500 ms timeout, applying them to the whole process tree:
- Generate a Control-C event on the application's console.
- Post
WM_CLOSEto the application's windows. - Post
WM_QUITto the application's threads. - Call
TerminateProcess().
| Parameter | Type | Meaning |
|---|---|---|
AppStopMethodSkip | REG_DWORD bitmask | Skip methods: 1 = no Control-C, 2 = no WM_CLOSE, 4 = no WM_QUIT, 8 = no TerminateProcess(). Avoid 8 — the application may then never exit. |
AppStopMethodConsoleAppStopMethodWindowAppStopMethodThreads | REG_DWORD (ms) | Per-method timeouts. The clock runs per process in the tree, so total shutdown can exceed the sum. |
Environment variables
| Parameter | Type | Meaning |
|---|---|---|
AppEnvironment | Multi-string | Replaces the service environment entirely. Previously defined variables cannot be referenced. |
AppEnvironmentExtra | Multi-string | Appends to the service environment. This is what most people want. |
Environment | Multi-string | Standard Windows service environment block (available to all services, not just NSSM). Merged into the system environment and sorted alphabetically first. |
Entries are KEY=VALUE pairs; variables are expanded in order, so
PATH=C:\bin;%PATH% works in AppEnvironmentExtra. On the
command line each pair is a separate argument, and +KEY=VALUE /
-KEY add/remove single variables:
nssm set myapp AppEnvironmentExtra JAVA_HOME=C:\jdk-17 nssm set myapp AppEnvironmentExtra +PATH=C:\apps\myapp\bin nssm set myapp AppEnvironmentExtra -JAVA_HOME
System service settings
These correspond to standard service registry values and can also be read or written for non-NSSM services:
| Parameter | Meaning |
|---|---|
DisplayName | Friendly name shown in services.msc. |
Description | Service description. |
Start | Startup type: SERVICE_AUTO_START, SERVICE_DELAYED_START, SERVICE_DEMAND_START, SERVICE_DISABLED. |
Type | SERVICE_WIN32_OWN_PROCESS (default) or SERVICE_INTERACTIVE_PROCESS (LocalSystem only). |
ObjectName | Account: nssm set <svc> ObjectName <user> <password>. Well-known accounts (LocalSystem, LocalService, NetworkService, NT Service\<svc>) need no password. |
DependOnServiceDependOnGroup | Dependencies, one per argument; prefix with +/- to add/remove individually, e.g. nssm set <svc> DependOnService +RpcSs. |
ImagePath | Path to the service executable (i.e. NSSM itself). |
Name | Read-only: the service's registry key name, useful when only the display name is known. |
Event hooks
NSSM can run your own commands in response to service events. Configure a hook
with nssm set <servicename> AppEvents <event>/<action> <command>
or set the registry string value
Parameters\AppEvents\<event>\<action> directly.
| Event/Action | Timing | Sync |
|---|---|---|
Start/Pre | Before the application is launched | Yes |
Start/Post | After the application starts successfully | No |
Stop/Pre | Before the application is killed | Yes |
Exit/Post | After the application exits and is cleaned up | No |
Rotate/Pre, Rotate/Post | Before/after online log rotation | Pre: yes |
Power/Change, Power/Resume | Power status changes / resume from standby | No |
Hooks run with the service's environment plus context variables such as
%NSSM_EXE%, %NSSM_SERVICE_NAME%, %NSSM_EVENT%,
%NSSM_EXITCODE% and many more; check %NSSM_HOOK_VERSION%
before using them. Example — restart the service when the system resumes:
nssm set myapp AppEvents Power/Resume "%NSSM_EXE% restart %NSSM_SERVICE_NAME%"
All hook environment variables (NSSM_HOOK_VERSION ≥ 1)
| Variable | Content |
|---|---|
NSSM_EXE | Path to NSSM itself |
NSSM_CONFIGURATION | Build information, e.g. 64-bit debug |
NSSM_VERSION | NSSM version |
NSSM_BUILD_DATE | NSSM build date |
NSSM_PID | PID of the running NSSM process |
NSSM_DEADLINE | Milliseconds after which the hook is killed |
NSSM_SERVICE_NAME | Service key name |
NSSM_SERVICE_DISPLAYNAME | Service display name |
NSSM_COMMAND_LINE | Command line used to launch the application |
NSSM_APPLICATION_PID | PID of the application (may be blank) |
NSSM_EVENT / NSSM_ACTION | Event class and action triggering the hook |
NSSM_TRIGGER / NSSM_LAST_CONTROL | Service control triggering / last handled |
NSSM_START_REQUESTED_COUNT | Start requests so far |
NSSM_START_COUNT | Successful starts so far |
NSSM_THROTTLE_COUNT | Slow starts since last successful start |
NSSM_EXIT_COUNT | Application exits so far |
NSSM_EXITCODE | Last application exit code (may be blank) |
NSSM_RUNTIME | Milliseconds NSSM has been running |
NSSM_APPLICATION_RUNTIME | Milliseconds the application has run since last start |
A Start/Pre hook returning exit code 99 aborts the start of the
application. Set AppRedirectHooks to 1 to send hook output to the
service's configured stdout/stderr. All hooks are killed after their deadline.
FAQ & troubleshooting
How is NSSM different from sc.exe or srvany?
sc.exe only creates service entries and expects the executable itself to speak the service protocol. srvany hosts arbitrary programs but never restarts them. NSSM hosts any program and supervises it: restart on failure, graceful shutdown, logging, throttling and per-exit-code policies.
Does NSSM support WinSW-style configuration files?
No. Configuration is stored in the registry, exactly like the original NSSM. For scripting use nssm set; to back up or clone a service use nssm dump, which prints a ready-to-run batch script recreating the configuration.
The service won't start
Check the Windows event log (Application log, source NSSM) for the exact error. Common causes: wrong AppDirectory, missing executable, a path with unquoted spaces, or the service account lacking permission on the application or log files.
Port conflicts
If the application starts but fails, check whether its port is already taken: netstat -ano | findstr <port> — the PID in the output identifies the conflicting process. Note that a previous instance may still be shutting down; nssm processes <servicename> shows what NSSM launched.
"Service is marked for deletion"
This fork's nssm remove stops the service and retries automatically. If it still fails, close tools holding service handles (services.msc, event viewer) and try again; the 2017-era workaround of rebooting is no longer necessary.
32-bit or 64-bit?
Use the 64-bit build on 64-bit Windows. The 32-bit build works everywhere but manages at most 32 CPUs for affinity and cannot read the paths of 64-bit processes with nssm processes on older Windows.
Which Windows versions are supported?
Release binaries are compiled with Visual Studio 2008 and run on Windows XP and later, both 32-bit and 64-bit. That makes NSSM a good fit for keeping legacy Windows 7 machines serving.
Where do NSSM's own messages go?
To the Windows event log, with a unique event ID per message type. Existing event IDs never change between versions. Your application's output goes wherever AppStdout/AppStderr point.
Is it really free?
Yes — NSSM is public domain. You may use it and its source code unconditionally, for any purpose.