How to Schedule a Python Script in Windows Task Scheduler

If you run Python scripts regularly—whether for data backups, automation, web scraping, report generation, or maintenance tasks—running them manually becomes a hassle. That’s where Windows Task Scheduler comes in. It lets you execute your Python script automatically at a specific time, when you log in, or whenever an event occurs.

The best part? You don’t need any third-party apps. Windows already includes everything you need to automate your Python workflow smoothly and reliably.

In this guide, we’ll walk you through exactly how to schedule a Python script in Task Scheduler on Windows 11. We’ll also show you how to use virtual environments, how to capture logs, and how to troubleshoot the most common issues.

How to Schedule a Python Script Using Task Scheduler

Windows Task Scheduler gives you two solid paths: using the GUI or using the schtasks command-line tool. Let’s start with the GUI option since it’s the easiest and most beginner-friendly.

1. Create a Wrapper Batch File (Strongly Recommended)

Task Scheduler doesn’t always run scripts with the correct working directory or Python interpreter. Creating a small batch file ensures everything runs exactly as expected.

If your script uses a global Python installation:

Create a .bat file (for example, run_script.bat) and add:

@echo off
cd /d "C:\path\to\your\project"
"C:\Python39\python.exe" "C:\path\to\your\project\myscript.py" >> "C:\path\to\logs\myscript.log" 2>&1

If your script uses a virtual environment:

@echo off
cd /d "C:\path\to\your\project"
call "C:\path\to\your\project\venv\Scripts\activate.bat"
python "C:\path\to\your\project\myscript.py" >> "C:\path\to\logs\myscript.log" 2>&1

This ensures:

  • Your project runs in the correct directory
  • Your virtual environment activates correctly
  • All output is logged for debugging

2. Open Task Scheduler and Create a New Task

  1. Open the Start Menu, type Task Scheduler, and launch it.
  2. On the right-hand panel, click Create Task.
  3. In the General tab:
    • Name your task clearly (e.g., “Run My Python Script”)
    • Select Run whether user is logged on or not
    • Choose Run with highest privileges if needed
    • Set Configure for to your Windows version

This ensures the task runs even when your session is locked.

3. Create the Trigger

A trigger determines when your script runs.

  1. Open the Triggers tab.
  2. Click New.
  3. Choose your schedule type, such as:
    • Daily at a specific time
    • At logon
    • At system startup
    • Weekly or Monthly
  4. Configure the time, date, or condition.
  5. Click OK.

Your script will now execute automatically based on the chosen schedule.

4. Add the Action to Run the Script

  1. Open the Actions tab.
  2. Click New.
  3. Set Action to Start a program.
  4. Enter the following:

If using a batch wrapper:

  • Program/script: C:\scripts\run_script.bat

If calling Python directly:

  • Program/script: C:\Python39\python.exe
  • Add arguments: "C:\path\to\myscript.py"
  1. Fill Start in with the project directory path.

This is a critical step. If you skip it, relative file paths inside your script may fail.

5. Adjust Conditions and Settings

In the Conditions tab:

  • Uncheck “Start the task only if the computer is on AC power” if you want it to run even on battery.
  • Disable idle-related requirements if the task must run exactly on time.

In the Settings tab:

  • Enable Run task as soon as possible after a scheduled start is missed
  • Enable If the task fails, restart every X minutes

These options make your task much more reliable.

6. Save and Test Your Task

  1. Click OK.
  2. If prompted, enter your Windows password.
  3. In the Task Scheduler Library, right-click your new task and select Run.

Check your log file or script output to ensure everything worked properly.

How to Schedule a Python Script Using schtasks (Advanced)

If you prefer command-line automation or want to deploy tasks via scripts, schtasks is your best option.

Create a daily scheduled task:

schtasks /Create /SC DAILY /TN "RunMyPython" /TR "C:\scripts\run_script.bat" /ST 03:00 /RL HIGHEST /F

Run at logon:

schtasks /Create /SC ONLOGON /TN "RunScriptAtLogon" /TR "C:\scripts\run_script.bat"

Force overwrite:

Add /F to replace an existing task.

This is perfect for remote servers, deployment scripts, and automated setups.

Troubleshooting Common Task Scheduler Problems

Here are fixes for the issues most users run into.

The task runs but nothing happens

  • Set Start in to the correct folder.
  • Use a .bat wrapper to control environment and paths.
  • Check logs for errors.

Script only works when you’re logged in

  • Use Run whether user is logged on or not.
  • Ensure the task does not require interactive input.

Virtual environment activation fails

  • Use the batch file method
  • Or call the venv-specific python.exe directly

No task history

  • Enable all task history from the right-hand Action panel.

Wrapping Up

Scheduling a Python script in Windows Task Scheduler is one of the most powerful ways to automate your workflow. Whether you’re generating daily reports, syncing data, or automating cleanup tasks, Task Scheduler can handle everything quietly in the background.

By creating a simple batch wrapper, setting the working directory, using absolute paths, and enabling logs, you ensure your automated tasks run reliably every time. Whether you’re using the GUI or the command line, you now have everything you need to automate any Python script in Windows 11.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.