← All recipes

Windows Scheduled Task Watchdog for a Local Service

Status: Draft

Last tested: TBD

Works with: Windows 10/11, Scheduled Tasks

Category: Windows / Reliability

Difficulty: Intermediate

Problem

Local automation services sometimes stop after updates, reboots, or crashes. A lightweight watchdog can check health and restart the service without needing a full service manager.

What you will build

A Windows Scheduled Task that runs every few minutes, checks whether a local endpoint or process is healthy, and starts it if needed.

Requirements

Quick version

schtasks /Create /TN "Example Service Watchdog" /TR "C:\Path\To\watchdog.cmd" /SC MINUTE /MO 5 /F

Example watchdog script

@echo off
setlocal
curl -fsS http://127.0.0.1:PORT/health >nul 2>&1
if %ERRORLEVEL% EQU 0 exit /b 0

rem Start the service if health check failed
start "" "C:\Path\To\start-service.cmd"
exit /b 0

Step-by-step setup

Step 1: Define the health check

Prefer an HTTP health endpoint if available. Otherwise check a process name with `tasklist`.

Step 2: Define the restart command

Use a script that starts the service in a controlled way.

Step 3: Create the scheduled task

schtasks /Create /TN "Example Service Watchdog" /TR "C:\Path\To\watchdog.cmd" /SC MINUTE /MO 5 /F

Step 4: Test failure recovery

Stop the service, run the watchdog, and confirm the service starts again.

Verification

Troubleshooting

| Symptom | Likely cause | Fix |

| --- | --- | --- |

| Task never runs | Task disabled or wrong trigger | Query with `schtasks /Query /V` |

| Service starts repeatedly | Health check URL wrong | Test `curl` manually |

| Window pops up | Using visible console start | Use `pythonw`, service wrapper, or minimized task settings |