NSSM

The Native System Service Manager

NSSM turns any executable into a proper Windows service — and keeps it running. If your application crashes or exits unexpectedly, NSSM restarts it automatically. It can capture output to log files, shut applications down gracefully, run them under any account, and much more. No configuration files, no dependencies: one executable and the registry.

v3.0.3 Public domain Windows XP and later x86 & x64 GUI + CLI

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.

Why no configuration file? Like the original NSSM, this fork stores configuration in the registry under 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.

  1. 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 myapp without an application path to open the GUI installer. Paths containing spaces must be quoted.

  2. 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"
  3. Start it

    nssm start myapp

    Check that it is running:

    nssm status myapp
    nssm processes myapp
  4. Manage it day to day

    nssm restart myapp
    nssm stop myapp
    nssm list

    You can also control the service with services.msc or sc.exe — NSSM services are ordinary Windows services.

  5. 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.exe there) to clone the service. nssm dump myapp myapp2 shows myapp's configuration but writes commands for a service named myapp2.

  6. Remove it

    nssm remove myapp confirm

    NSSM stops the service first, then deletes it. No reboot needed even if the service was running.

GUI alternative: run 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.

CommandSyntaxDescription
installnssm install <servicename> [<app> [<args>]]Install a service. With an application path the service is created directly; without one, the GUI installer opens.
removenssm remove <servicename> [confirm]Stop and delete a service. Without confirm a GUI confirmation is shown. delete is an alias.
editnssm edit <servicename>Open the GUI editor for an installed service.
getnssm get <servicename> <parameter>Print the current value of a parameter.
setnssm set <servicename> <parameter> <value>Set a parameter. All remaining arguments are concatenated with spaces to form the value.
resetnssm reset <servicename> <parameter>Restore a parameter to its default. unset is an alias.
dumpnssm dump <servicename> [<newname>]Print batch commands which recreate the service's configuration, properly quoted and escaped.
startnssm start <servicename>Start the service.
stopnssm stop <servicename>Stop the service.
restartnssm restart <servicename>Stop, then start the service.
pausenssm pause <servicename>Pause the service (also pauses restart attempts).
continuenssm continue <servicename>Resume a paused service.
statusnssm status <servicename>Print the service state, e.g. SERVICE_RUNNING. Exit code 0 on success.
statuscodenssm statuscode <servicename>Exit with the numeric service state, e.g. 4 for SERVICE_RUNNING. Useful in scripts.
rotatenssm rotate <servicename>Trigger an on-demand log rotation (requires online rotation to be enabled).
listnssm list [all]List services managed by NSSM; with all, list every service on the system.
processesnssm processes <servicename>Show PID and executable path of the processes launched by a service.
versionnssm versionPrint 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

ParameterTypeMeaning
ApplicationPathFull path of the program to run. Relative paths are resolved against the directory NSSM was started from.
AppParametersStringCommand-line arguments passed to the application.
AppDirectoryPathWorking directory for the application.
AppExitStringAction when the application exits. See exit actions. Set per exit code via nssm set <svc> AppExit <code> <action>.

Process control

ParameterTypeMeaning
AppThrottleREG_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.
AppRestartDelayREG_DWORD (ms)Unconditional pause before restarting the application, even after a clean run. The longer of this and the throttle period applies.
AppPriorityREG_DWORDPriority class, e.g. set with nssm set <svc> AppPriority NORMAL_PRIORITY_CLASS. Values: REALTIME, HIGH, ABOVE_NORMAL, NORMAL, BELOW_NORMAL, IDLE (_PRIORITY_CLASS suffix).
AppAffinityREG_SZComma-separated, zero-indexed CPU list with optional ranges, e.g. 0-2,4. 32-bit NSSM manages at most 32 CPUs.
AppNoConsoleREG_DWORDSet to 1 to suppress the console window NSSM creates by default.
AppKillProcessTreeREG_DWORDSet to 0 to apply stop methods only to the main process instead of the whole process tree.

I/O redirection

ParameterTypeMeaning
AppStdin
AppStdout
AppStderr
PathFiles 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
ShareMode, CreationDisposition,
FlagsAndAttributes
REG_DWORDFine-tune the CreateFile() call used to open each stream, e.g. AppStdoutShareMode, AppStdoutCreationDisposition, AppStdoutFlagsAndAttributes. Sensible defaults apply when omitted.
AppTimestampLogREG_DWORDSet 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

ParameterTypeMeaning
AppRotateFilesREG_DWORDSet non-zero to enable rotation. The existing file is renamed with a timestamp suffix, e.g. nssm-20131221T113939.457.log.
AppRotateOnlineREG_DWORDSet 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.
AppRotateSeconds
AppRotateBytes
AppRotateBytesHigh
REG_DWORDSkip 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.
AppRotateDelayREG_DWORD (ms)Pause after rotating, so log readers can notice the size change.
AppStdoutCopyAndTruncate
AppStderrCopyAndTruncate
REG_DWORDRotate 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>.

ValueBehaviour
RestartRestart the application (default behaviour).
IgnoreKeep the service running even though the application exited (srvany emulation — usually undesirable).
ExitStop the service cleanly so Windows recovery actions can take over.
SuicideSimulate 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:

  1. Generate a Control-C event on the application's console.
  2. Post WM_CLOSE to the application's windows.
  3. Post WM_QUIT to the application's threads.
  4. Call TerminateProcess().
ParameterTypeMeaning
AppStopMethodSkipREG_DWORD bitmaskSkip methods: 1 = no Control-C, 2 = no WM_CLOSE, 4 = no WM_QUIT, 8 = no TerminateProcess(). Avoid 8 — the application may then never exit.
AppStopMethodConsole
AppStopMethodWindow
AppStopMethodThreads
REG_DWORD (ms)Per-method timeouts. The clock runs per process in the tree, so total shutdown can exceed the sum.

Environment variables

ParameterTypeMeaning
AppEnvironmentMulti-stringReplaces the service environment entirely. Previously defined variables cannot be referenced.
AppEnvironmentExtraMulti-stringAppends to the service environment. This is what most people want.
EnvironmentMulti-stringStandard 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:

ParameterMeaning
DisplayNameFriendly name shown in services.msc.
DescriptionService description.
StartStartup type: SERVICE_AUTO_START, SERVICE_DELAYED_START, SERVICE_DEMAND_START, SERVICE_DISABLED.
TypeSERVICE_WIN32_OWN_PROCESS (default) or SERVICE_INTERACTIVE_PROCESS (LocalSystem only).
ObjectNameAccount: nssm set <svc> ObjectName <user> <password>. Well-known accounts (LocalSystem, LocalService, NetworkService, NT Service\<svc>) need no password.
DependOnService
DependOnGroup
Dependencies, one per argument; prefix with +/- to add/remove individually, e.g. nssm set <svc> DependOnService +RpcSs.
ImagePathPath to the service executable (i.e. NSSM itself).
NameRead-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/ActionTimingSync
Start/PreBefore the application is launchedYes
Start/PostAfter the application starts successfullyNo
Stop/PreBefore the application is killedYes
Exit/PostAfter the application exits and is cleaned upNo
Rotate/Pre, Rotate/PostBefore/after online log rotationPre: yes
Power/Change, Power/ResumePower status changes / resume from standbyNo

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)
VariableContent
NSSM_EXEPath to NSSM itself
NSSM_CONFIGURATIONBuild information, e.g. 64-bit debug
NSSM_VERSIONNSSM version
NSSM_BUILD_DATENSSM build date
NSSM_PIDPID of the running NSSM process
NSSM_DEADLINEMilliseconds after which the hook is killed
NSSM_SERVICE_NAMEService key name
NSSM_SERVICE_DISPLAYNAMEService display name
NSSM_COMMAND_LINECommand line used to launch the application
NSSM_APPLICATION_PIDPID of the application (may be blank)
NSSM_EVENT / NSSM_ACTIONEvent class and action triggering the hook
NSSM_TRIGGER / NSSM_LAST_CONTROLService control triggering / last handled
NSSM_START_REQUESTED_COUNTStart requests so far
NSSM_START_COUNTSuccessful starts so far
NSSM_THROTTLE_COUNTSlow starts since last successful start
NSSM_EXIT_COUNTApplication exits so far
NSSM_EXITCODELast application exit code (may be blank)
NSSM_RUNTIMEMilliseconds NSSM has been running
NSSM_APPLICATION_RUNTIMEMilliseconds 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.