Easy Steps to Automate Python Scripts with Task Scheduler on Windows
Cover Image

Every developer hits a point where manual execution becomes a liability. Whether scraping data nightly, compiling reports, or running automated testing pipelines, waiting for scripts to complete wastes time. Windows Task Scheduler remains a robust, zero-cost automation engine in 2026.
This guide covers how to set up hands-free Python automation on Windows in a reliable, production-ready way.
1. Bulletproof the Python Script
Scripts that run perfectly in an interactive terminal often crash when executed in the background by a scheduled task. This usually stems from path resolution failures or suppressed exceptions.
Use Absolute Paths: Do not rely on the current working directory (cwd). Use pathlib to resolve absolute paths relative to the script file.
from pathlib import Path
script_dir = Path(__file__).parent
data_file = script_dir / 'output' / 'data.csv'
Add File Logging: Print statements disappear in background execution. Bind a logger to a .log file to capture tracebacks.
import logging
logging.basicConfig(filename=script_dir/'task.log', level=logging.INFO,
format='%(asctime)s %(levelname)s: %(message)s')
2. Write the Execution Wrapper (Batch File)
Task Scheduler triggers programs, not Python files directly. Writing a small .bat wrapper ensures the correct Python interpreter executes the script, which is critical if you use virtual environments (.venv).
Create run_script.bat in your project folder:
@echo off
cd /d "C:\Path\To\Your\Project"
call .venv\Scripts\activate
python main_script.py
exit
Note: Using call ensures the virtual environment activates properly before the second command runs.
3. Configure the Windows Task Scheduler
Press Win + R, type taskschd.msc, and hit Enter.
- Click Create Task (not "Create Basic Task" — we need advanced settings immediately).
- General Tab: Name the task "Daily Python Scraper". Select "Run whether user is logged on or not" (requires your Windows password) so scripts run even if the machine restarts. Check "Run with highest privileges" if the script modifies system files.
- Triggers Tab: Click New. Set the schedule (e.g., Daily at 3:00 AM).
- Actions Tab: Click New.
- Action: Start a program
- Program/script: browse and select your run_script.bat.
- Start in: Enter the absolute path to your project folder (e.g., C:\Path\To\Your\Project). This prevents lingering directory issues.
- Settings Tab: Check "Allow task to be run on demand". Check "Stop the task if it runs longer than 1 hour" to prevent zombie background processes from draining system memory.
4. Test and Monitor
Do not wait for the scheduled time to verify your setup. Right-click the new task and select Run.
Watch the History tab (you may need to enable "All Tasks History" in the right-hand panel). A return code of 0 typically means success. If it fails, check the .log file your Python script generated.
By offloading repetitive execution to Task Scheduler, you ensure scripts run consistently, accurately, and entirely hands-free.
