Auto-Restart MT4 and MT5 After Windows Update Reboots Your VPS

Bring MetaTrader back on its own after a Windows Update restart. Set up auto-logon, a watchdog scheduled task and planned update windows on your Windows VPS.

dns WindowsVPS Team calendar_today schedule5 min read
Auto-Restart MT4 and MT5 After Windows Update Reboots Your VPS
tocOn this page 7 sections
  1. Why MetaTrader stays closed after a reboot
  2. Step 1: Sign in automatically at boot
  3. Step 2: Write a watchdog script
  4. Step 3: Register the scheduled task
  5. Step 4: Restart only when the market is closed
  6. Step 5: Test it and confirm what happened
  7. FAQ

To bring MetaTrader back after a Windows Update reboot, you need three things. The VPS has to sign in to a desktop session by itself. A scheduled task has to start each terminal when that session opens. A watchdog check should relaunch any terminal that isn't running. Add an update schedule that only restarts the server when the market is closed, and a forced reboot stops costing you trades.

Why MetaTrader stays closed after a reboot

MT4 and MT5 are desktop programs, not services. They need a user to be signed in to an interactive desktop. When Windows Update restarts the VPS, the server comes back to the logon screen and waits. Nobody is signed in, so nothing in your Startup folder or any per-user autostart runs. Your Expert Advisors stay offline until you connect over RDP, and that could be hours later.

The fix is to get from boot to a running terminal without any input from you. Each step below handles one part of that.

Step 1: Sign in automatically at boot

Use a dedicated, non-administrator Windows account for trading and set it to sign in automatically. The easiest safe option is Microsoft's Sysinternals Autologon tool. It stores the password as an encrypted LSA secret, not as plain text in the registry. Run it once over RDP, enter the account name, domain (or the computer name for a local account) and password, then click Enable.

Don't set DefaultPassword under the Winlogon registry key by hand. That leaves the password readable to anyone who can read the registry. Auto-logon means anyone with console access gets a signed-in desktop, so pair it with a strong RDP password and the usual hardening.

Important: when you finish an RDP session, disconnect. Don't sign out. Signing out closes the session and every terminal in it. On Windows Server, a user is limited to one session by default, so your next RDP connection takes over the same desktop that auto-logon created.

Step 2: Write a watchdog script

One script can handle both cases: the first launch after boot, and a terminal that crashed later. Save it as C:\Scripts\mt-watchdog.ps1 and list the full path of every terminal you run:

$terminals = @(
  'C:\MT5-Main\terminal64.exe',
  'C:\MT4-Hedge\terminal.exe'
)
$running = Get-Process -Name terminal, terminal64 -ErrorAction SilentlyContinue |
  Select-Object -ExpandProperty Path
foreach ($t in $terminals) {
  if ($running -notcontains $t) {
    Start-Process -FilePath $t -ArgumentList '/portable' -WorkingDirectory (Split-Path $t)
  }
}

The script checks each terminal by its full path, not just its process name. That way it can tell several copies of MetaTrader apart. Only use /portable if you installed the terminals in portable mode. If you didn't, remove that argument.

Step 3: Register the scheduled task

Run this in PowerShell while signed in as the trading account. It creates one task with two triggers: one at logon (with a delay so networking and the desktop can finish loading), and one that repeats every five minutes:

$action = New-ScheduledTaskAction -Execute 'powershell.exe' `
  -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\Scripts\mt-watchdog.ps1'
$atLogon = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$atLogon.Delay = 'PT45S'
$repeat = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
$settings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew -StartWhenAvailable
Register-ScheduledTask -TaskName 'MT Watchdog' -Action $action `
  -Trigger $atLogon, $repeat -Settings $settings -User $env:USERNAME -RunLevel Limited

The task has no stored password, so it runs only while the account is signed in, inside that account's desktop. That's what you want, because terminals started from a background session would be invisible and could misbehave. If you run several terminals on a small plan, you can also stagger their start times or lower their priority, as covered in setting scheduled task priority on a Windows Server VPS. For apps you only want started when an admin connects, see launching apps automatically at RDP sign-in.

Step 4: Restart only when the market is closed

Auto-recovery covers you when a reboot happens. It's still better to choose when it happens. On Windows Server you can:

  • Open sconfig and set Windows Update to download only, then install and reboot yourself during the weekend market close.
  • Or use Group Policy (Configure Automatic Updates) to schedule installs for a fixed day and hour, such as early Saturday.
  • Set active hours wide enough to cover your trading sessions, so Windows doesn't restart during them.

Don't turn off updates completely. A trading VPS that's missing patches and has RDP open to the internet is a bigger risk than a planned weekend reboot.

Step 5: Test it and confirm what happened

Don't wait for the next Patch Tuesday to find out whether this works. Run Restart-Computer yourself, wait a few minutes, then reconnect over RDP. Every terminal should be open, connected to its broker, and showing the AutoTrading (Algo Trading) button turned on. To check why and when the server last restarted, and whether the watchdog ran:

Get-WinEvent -FilterHashtable @{LogName='System'; Id=1074} -MaxEvents 5 |
  Format-List TimeCreated, Message
Get-ScheduledTaskInfo -TaskName 'MT Watchdog'

Event 1074 records who or what started each restart, including Windows Update. A LastTaskResult of 0 means the watchdog's last run finished without errors. For more setup advice for trading servers, see our Windows VPS for forex trading page.

FAQ

Can I run MetaTrader as a Windows service instead?

Not reliably. MetaTrader expects a real user desktop, and wrapping it in a service usually causes problems with charts, EAs or saving settings. Auto-logon plus a scheduled task is the more dependable approach.

Will my EAs come back on the charts after a restart?

Usually yes. The terminal reopens its last profile, and that includes the attached EAs. Check that algo trading is still enabled after your first test reboot. If your EAs need DLL imports, confirm that setting too.

Does the watchdog window flash every five minutes?

A PowerShell window can show for a moment even with -WindowStyle Hidden. It doesn't affect the terminals. If it bothers you while you're connected, increase the repeat interval to ten or fifteen minutes.

Run this on your own Windows VPS

Get a Windows VPS from WindowsVPS in about 60 seconds, with full Administrator access over RDP, NVMe storage and the Windows license included.

Buy a Windows VPS →

dns

Written by the WindowsVPS Team

We run Windows Server VPS hosting and write these guides from the same setups our customers use: RDP, PowerShell, trading terminals and always-on bots. Questions about a guide? Contact us.

About WindowsVPS Windows VPS guides All articles

Ready to deploy your server?

Windows or Linux VPS — up and running in under 60 seconds.