Windows Server

Run Programs 24/7 on Windows Server: Auto-Start with Task Scheduler, NSSM Services and Auto-Restart

5 steps 12 min read 6 views 0
On this page

Programs started from a Remote Desktop session stop when that session signs out and do not come back after a reboot. Bots, game servers, Node.js or Python applications, data collectors and trading tools should instead start automatically with Windows and restart by themselves if they crash. This guide shows three reliable ways to do that on Windows Server: Task Scheduler, the free service wrapper NSSM, and Windows' own service recovery settings.

Closing the Remote Desktop window (disconnecting) leaves your programs running, but choosing Sign out, an automatic session time limit or a reboot closes them. Do not rely on an open session for anything that must run 24/7.

Which Method Should I Use?

MethodBest forRestarts on crashNeeds a logged-in desktop
Task Scheduler "At startup"Scripts and console programsYes (retry settings)No
NSSM serviceLong-running console apps (Node.js, Python, Java, game servers)Yes, immediatelyNo
Auto-logon + Startup folderPrograms that need a visible window or GUINoYes

Method 1: Task Scheduler at Startup

Open taskschd.msc and choose Create Task (not "Basic Task"):

  1. General: select Run whether user is logged on or not and Run with highest privileges.
  2. Triggers: New → At startup; optionally Delay task for 30 seconds so the network is ready.
  3. Actions: Start a program, with the full path to the program or script and the folder in Start in.
  4. Settings: tick If the task fails, restart every 1 minute, up to 999 times, and set Stop the task if it runs longer than to off for long-running programs.

The same task from PowerShell:

$action   = New-ScheduledTaskAction -Execute "C:\apps\collector\collector.exe" -WorkingDirectory "C:\apps\collector"
$trigger  = New-ScheduledTaskTrigger -AtStartup
$trigger.Delay = "PT30S"
$settings = New-ScheduledTaskSettingsSet -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) `
            -ExecutionTimeLimit ([TimeSpan]::Zero) -StartWhenAvailable
Register-ScheduledTask -TaskName "Collector" -Action $action -Trigger $trigger -Settings $settings `
            -User "SYSTEM" -RunLevel Highest

Start-ScheduledTask -TaskName "Collector"
Get-ScheduledTaskInfo -TaskName "Collector"   # LastTaskResult 0 = success

Method 2: Run Any Program as a Service with NSSM

NSSM (the Non-Sucking Service Manager) wraps any executable as a real Windows service, restarts it immediately if it exits and can write its console output to log files. Download it from nssm.cc, copy nssm.exe (from the win64 folder) to C:\Windows\System32, then:

# Example: a Node.js application
nssm install MyApp "C:\Program Files\nodejs\node.exe" "C:\apps\myapp\server.js"
nssm set MyApp AppDirectory C:\apps\myapp
nssm set MyApp AppStdout C:\apps\myapp\logs\out.log
nssm set MyApp AppStderr C:\apps\myapp\logs\error.log
nssm set MyApp AppRotateFiles 1
nssm set MyApp AppRotateBytes 10485760
nssm set MyApp Start SERVICE_AUTO_START
nssm start MyApp

nssm status MyApp
nssm restart MyApp
nssm edit MyApp       # graphical editor for all settings
nssm remove MyApp confirm

For a Python script use the path of python.exe with the script as the argument; for Java use java.exe with -jar app.jar. If the program needs access to network shares or a user profile, set the account on the Log on tab of nssm edit instead of LocalSystem.

Method 3: Recovery Settings for Existing Services

For a program that already installs itself as a service (a database, a game server, an agent), tell Windows to restart it automatically when it fails:

# Restart after 5 seconds on the first three failures; reset the failure counter after one day
sc.exe failure "MyService" reset= 86400 actions= restart/5000/restart/5000/restart/5000
sc.exe failureflag "MyService" 1
sc.exe config "MyService" start= auto
sc.exe qfailure "MyService"

The same options are on the Recovery tab of the service in services.msc.

Programs That Need a Desktop Window

Services run in an isolated session without a visible desktop, so GUI programs that must show a window (some trading terminals, game clients, automation tools) will not work as services. For these, enable automatic sign-in for a dedicated user with Microsoft's Sysinternals Autologon tool (it stores the password encrypted), put a shortcut to the program in shell:startup for that user, and disconnect rather than sign out when you leave the Remote Desktop session. Also exclude that user from automatic sign-out time limits.

FAQ

The task shows "Running" but my program is not working

Check that Start in (or the NSSM AppDirectory) is set: many programs look for config files relative to the working directory. Also check the program's own logs, and for NSSM the AppStderr file.

The service starts, then stops immediately

Run the exact same command manually in a PowerShell window to see the error. For services, also look in Event Viewer → Windows Logs → System and Application.

Will these survive Windows Update reboots?

Yes. Startup tasks and automatic services start again after every reboot, which is exactly why they are better than an open Remote Desktop session. See managing Windows Update to control when reboots happen.

Still stuck after following these steps? Open a support ticket and the IMIDC 24/7 technical team will help. Include the server IP, the Windows Server version, the program you want to run and the exact error or event log entry so we can pinpoint the issue faster.

Was this answer helpful?

Related Tutorials