How to Run a Python Script Automatically on Windows Startup

Published on: May 19, 2026
Reading time: 8 minutes
Script Python configurado para iniciar junto com o Windows

Imagine waking up to find your Python script has already organized your files, generated a report, and checked for important updates, all before you even touched the keyboard. Learning how to run a Python script automatically on Windows startup is a fundamental step for anyone who wants to take Python automation seriously. Instead of opening a terminal every morning and typing the same command, you configure Windows to do that invisibly the moment the machine boots. This guide covers every method available, from the simplest to the most powerful, so you can choose the one that fits your project best.

Why Automate Script Startup on Windows?

The main reason is productivity. Many business processes depend on routines that must run daily without fail. If you work with data analysis, you might have a script that pulls information from a database and generates a fresh report early in the morning. If you use Python to monitor prices or web pages, automatic execution guarantees that no market movement goes undetected. Beyond convenience, automation eliminates human error. Forgetting to run an important task is no longer possible when the machine handles it on its own. This is especially relevant for Python beginners who are building their first real automation tools and want them to work reliably without constant supervision.

Method 1: The Windows Startup Folder

This is the simplest and most classic method. Everything placed inside the user startup folder executes automatically when that user logs into Windows. It is ideal for scripts that display a graphical interface or print messages to the terminal for the user to see.

Step-by-Step Using the Startup Folder

  1. Press Windows + R on your keyboard to open the Run dialog.
  2. Type shell:startup and press Enter. This opens the startup folder specific to your current user account.
  3. Create a shortcut to your .py file inside this folder, or drop a .bat launcher file there.

There is an important technical detail here. If you simply place the Python file there, Windows may try to open it with a text editor if file associations are not set correctly. The safest approach is to create a .bat batch file that explicitly calls the Python interpreter. If Python is not correctly configured in your system PATH, check the guide on installing Python on Windows to fix the “command not recognized” error before proceeding.

Method 2: Windows Task Scheduler

The Task Scheduler is the most robust tool for automating script execution on Windows. It supports specific triggers such as at system startup, at user login, at a fixed time, or even when the computer becomes idle. According to the official Microsoft Task Scheduler documentation, tasks can run whether or not a user is logged in, making this the right choice for scripts that need to operate on servers or unattended machines.

Configuring Task Scheduler Step by Step

  1. Open the Start Menu and search for “Task Scheduler”.
  2. In the right panel, click “Create Basic Task”.
  3. Give the task a name, such as “My Python Bot”.
  4. Choose the trigger. For automatic startup, select “When the computer starts” or “When I log on”.
  5. Under “Action”, choose “Start a program”.
  6. In the “Program/script” field, enter the full path to the Python executable, for example C:Python39python.exe.
  7. In the “Add arguments” field, enter the full path to your script, for example C:MyScriptsscript.py.

Using the full path to the Python executable is critical. If you use a Python virtual environment, point to the Python binary inside that environment’s Scripts folder instead of the global interpreter. This ensures all the libraries your script depends on are available when the task runs.

The Role of .bat Files in Startup Automation

A batch file acts as a launcher bridge. Instead of pointing the Task Scheduler directly at Python, many developers prefer creating a .bat file that first activates the virtual environment and then runs the script. This is very useful for preventing the ModuleNotFoundError, since it guarantees all libraries are loaded from the correct environment before execution begins:

@echo off
cd C:pathtoyourproject
C:pathtoyourvenvScriptspython.exe script.py
pause

The pause command at the end is optional but useful during testing, because it keeps the terminal window open so you can read any error messages before the window closes. Remove it in production once the script is confirmed to be working correctly.

Running Scripts Silently in the Background

In many automation scenarios, you do not want a black terminal window appearing every time the script starts. To solve this, rename your script file from .py to .pyw. The pythonw.exe executable is designed to run Python scripts without opening a console window. This is excellent for monitoring bots, background data collectors, and tools that react to system events without user interaction. In Task Scheduler, switching to pythonw.exe makes the process run silently in the Windows Task Manager, without interrupting the user’s visual workflow at all.

Handling Administrator Permissions

Depending on what your script does, such as modifying system files or accessing protected folders, you may encounter a PermissionError in Python. In Task Scheduler, there is an option called “Run with highest privileges” in the General tab of the task settings. Check that box if your script needs administrator access to function correctly. Be aware that tasks running without a logged-in user may have restricted access to network drives, which is a common source of confusion for scripts that work fine interactively but fail when scheduled.

Complete Project Code: Startup Verification Logger

To confirm that your startup configuration works, use this script. It writes a timestamped log entry to a file in your user directory every time it is launched. After rebooting, check the log file to confirm the script ran automatically:

import datetime
import os
import platform

def log_startup():
    # Save the log to the user's home folder to avoid permission issues
    log_path = os.path.join(os.path.expanduser("~"), "python_startup_log.txt")

    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    system = platform.system()

    entry = f"Script started successfully at: {timestamp} | System: {system}n"

    with open(log_path, "a", encoding="utf-8") as log_file:
        log_file.write(entry)

    print(f"Log saved to: {log_path}")

if __name__ == "__main__":
    log_startup()

After rebooting your computer, open python_startup_log.txt in your home directory. Each restart appends a new timestamped line. If the file is empty or missing, the startup configuration did not trigger and you need to revisit the Task Scheduler settings or the .bat file path. Learning to run terminal commands with Python can also help you diagnose startup issues by programmatically checking paths and process status.

Method Comparison

MethodEase of SetupRuns Without Login?Best Use Case
Startup FolderVery easyNoScripts for personal daily automation
Task SchedulerMediumYesServers, unattended machines, precise scheduling
.bat + Startup FolderEasyNoScripts that need virtual environment activation
Windows ServiceComplexYesProduction-grade services that must run 24/7

Managing Long-Running Scripts

If your script contains an infinite loop (such as a monitoring bot or a Discord bot), it will keep running indefinitely after startup. It is vital to add proper logging so that if the script crashes silently you can investigate why without needing to be at the computer when it happens. Using try and except in Python blocks throughout your code is mandatory in these cases, preventing the process from dying quietly due to a network timeout or a missing file.

For scripts that need to be stopped and restarted cleanly, consider wrapping them in a Windows service using the pywin32 library. This gives you service management commands (start, stop, restart) directly from the Services panel and ensures the script restarts automatically if it crashes. For containerized deployments, running the script inside Docker with a restart policy is the modern equivalent.

Frequently Asked Questions

My script does not start when I boot the PC. What should I check?

Verify that the Python interpreter path in Task Scheduler is correct and points to the right environment. Test the full command manually in CMD first by pasting the exact Program/script path and argument to confirm it works before relying on the scheduler.

How do I run the script without opening the terminal window?

Save your file with the .pyw extension instead of .py. This instructs Windows to use pythonw.exe, which runs the script with no console window attached.

Does Task Scheduler work if I am not logged in?

Yes. In the task’s General settings, select “Run whether user is logged on or not” and provide your user account password. This allows the task to execute at boot even on a headless or locked machine.

How do I make sure Pandas, Requests, and other libraries are available?

Point the Task Scheduler to the Python executable inside your virtual environment’s Scripts folder, not the global Python. All libraries installed in that environment will be available automatically.

Is there a limit to how many startup scripts I can have?

Windows has no strict limit, but each script consumes RAM and CPU on startup. Many heavy scripts launching simultaneously can slow the boot significantly. Use Task Scheduler’s delay option to stagger their start times.

The shell:startup command is not working. Is there another path?

Navigate manually to C:UsersYourUsernameAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup, replacing YourUsername with your actual account name. Place your shortcut or .bat file there directly.

How do I stop a script that is running silently in the background?

Open Task Manager with Ctrl + Shift + Esc, find “Python” in the Processes tab, and click “End Task”. If you scheduled it through Task Scheduler, you can also right-click the task there and choose “End”.

Can I use Docker instead of Task Scheduler for this on Windows?

Yes. Configure Docker Desktop to start with Windows and set your container’s restart policy to “always”. This is the most reliable production approach for long-running scripts that need to be resilient to crashes and reboots.

Share:

Facebook
WhatsApp
Twitter
LinkedIn

Article content

    Related articles

    Web scraper de notícias em Python com envio para Telegram
    Automation and Scripts
    Foto de perfil de Leandro Hirt da Academify

    Build a News Scraper to Telegram with Python

    Learn how to build a Python web scraper that extracts news headlines and sends them to Telegram automatically. Complete guide

    Ler mais

    Tempo de leitura: 9 minutos
    12/05/2026
    Acesso e edição de Google Sheets com Python
    Automation and Scripts
    Foto de perfil de Leandro Hirt da Academify

    Access and Edit Google Sheets with Python

    Learn to access and edit Google Sheets with Python using gspread, including API setup, authentication, reading, writing, and automation.

    Ler mais

    Tempo de leitura: 9 minutos
    12/05/2026
    Extração de texto de arquivos PDF usando Python
    Automation and Scripts
    Foto de perfil de Leandro Hirt da Academify

    Extract Text from PDFs with Python

    Learn how to extract text from PDFs with Python using PyPDF2 and pdfplumber. This complete guide covers single-page reading, table

    Ler mais

    Tempo de leitura: 9 minutos
    12/05/2026
    Automação de postagens no Twitter usando Python
    Automation and Scripts
    Foto de perfil de Leandro Hirt da Academify

    Tweepy: How to Automate Twitter Posts with Python

    Learn how to automate Twitter posts with Python using Tweepy. This complete guide covers API setup, authentication, scheduling tweets, sending

    Ler mais

    Tempo de leitura: 8 minutos
    12/05/2026
    Imagem ilustrativa de conteúdo Python para YouTube
    Automation and Scripts
    Foto de perfil de Leandro Hirt da Academify

    How to Download YouTube Videos with Python in 5 Minutes

    Learn how to download YouTube videos with Python in 5 minutes using pytube. This guide covers resolution selection, audio-only downloads,

    Ler mais

    Tempo de leitura: 8 minutos
    12/05/2026
    Uso de multiprocessing em Python para acelerar scripts
    Automation and Scripts
    Foto de perfil de Leandro Hirt da Academify

    How to Use Multiprocessing in Python to Speed Up Scripts

    Learn how to use Python's multiprocessing module to run tasks in parallel across all CPU cores. This guide covers Process,

    Ler mais

    Tempo de leitura: 9 minutos
    12/05/2026