Keep a Program Running on Windows Server

What happens to a program that you started in your Remote Desktop session:

  • You close the Remote Desktop window or choose Disconnect: the program keeps running. Next time you connect, it is still there.
  • You sign out: the program is closed.
  • The server restarts (for example after Windows Update): the program is closed and does not start again by itself.

So that your program starts by itself after every restart, without anybody signing in, create a task that starts it when Windows starts.


Start a Program When Windows Starts

Open PowerShell as administrator (right-click Start → Terminal (Admin)) and run, with the path of your program and its folder:

$action = New-ScheduledTaskAction -Execute "C:\MyApp\start.bat" -WorkingDirectory "C:\MyApp"
$trigger = New-ScheduledTaskTrigger -AtStartup
Register-ScheduledTask -TaskName "My app" -Action $action -Trigger $trigger -User "SYSTEM" -RunLevel Highest

Windows answers with the task and Ready.

PowerShell: the startup task My app is ready

The task starts the program after every start of Windows, before anybody signs in. It runs as SYSTEM, with full rights and without a window: you do not see the program on the desktop, but it runs. If your program needs a window or the files of your user, see the note below.

The task is also listed in Task Scheduler (Windows key + R → taskschd.msc → Task Scheduler Library), with the trigger At system startup. There you can start it at once with Run, stop it with End or delete it.

Task Scheduler Library with the task My app and the trigger At system startup

Test it: restart the server (How to Restart Windows Server) and check that your program runs, for example in Task Manager → Details.

Remove the Task

Unregister-ScheduledTask -TaskName "My app" -Confirm:$false
A program that needs a window

Some programs only work with a visible window. For them, create the task in Task Scheduler with Create Task, choose your user, Run only when user is logged on and the trigger At log on. The program then starts when you sign in with Remote Desktop; afterwards, close the window with Disconnect, not Sign out.


Related Guides

View all Windows guides

Was this answer helpful? 0 Users Found This Useful (0 Votes)