Running programs automatically on a Windows server
Here's how to keep a game server or bot running on a Windows server. It covers what to watch out for when closing the Remote Desktop window, starting again automatically when a program stops, and starting automatically after the server reboots.
Know this first: "Disconnect" and "Sign out" are different
- If you close the Remote Desktop window with the X button, only the connection is cut, and programs on the server keep running.
- If you click Start → Sign out inside the server, every program you started shuts down.
When you want to leave with your programs still running, close the window with its X button.
1. Start again automatically when it stops
Create a .bat file so the program runs again even if it stops because of an error. Type the following into Notepad, change the file type to "All files", and save it as start.bat.
@echo off
cd /d C:\myserver
:loop
java -Xmx4G -jar server.jar nogui
echo Server stopped. Restarting in 10 seconds...
timeout /t 10
goto loop
- Change
C:\myserverto the folder your program is in, and thejava ...line to your actual start command. (e.g.,node index.jsfor a Node.js bot) - To stop it completely, close the window, or press
Ctrl + Cand then typeY.
2. Start automatically when the server reboots
When the server reboots, for example for Windows Update, programs don't come back on while no one is logged in. If you register the program in Task Scheduler, it runs automatically when the server starts.
- Open Task Scheduler from the Start menu.
- Click Create Task on the right.
- General tab
- Name: something easy to recognize (e.g.,
My Server) - Select Run whether user is logged on or not
- Check Run with highest privileges
- Name: something easy to recognize (e.g.,
- Triggers tab → New → Begin the task: At startup → OK
- Actions tab → New
- Program/script: the
C:\myserver\start.batyou created above - Start in:
C:\myserver(Be sure to fill this in. If you leave it blank, the program often can't find its files.)
- Program/script: the
- On the Settings tab, uncheck the option that stops the task if it runs longer than a set time (3 days by default). If it stays checked, the program shuts down after 3 days.
- Click OK and enter the server account's password.
A program started this way runs in the background without a window on screen. To check whether it's running, look for
java.exe,node.exe, etc. on the Details tab in Task Manager. To stop it, select the task in Task Scheduler and click End.
If you want to see the window while you use it
For a program where you need to watch the console window and type commands, register it to run when you log in.
Win + R→ typeshell:startup→ OK- Put a shortcut to
start.batin the folder that opens. (Drag the file with the right mouse button and choose "Create shortcuts here")
With this method, it only runs once you log in with Remote Desktop. If the server has rebooted, connect to it once.
See also
- For Korea time and Korean language settings, see Setting up Korean language and Korea time on a Windows server.
- If the program needs to be reached from outside, also check Opening firewall ports.