To run a Python program automatically using Windows Task Scheduler, follow these steps:
Create a Python Script:
Ensure you have a Python script (.py file) that you want to run. For example,example.py
.Open Task Scheduler:
- Press
Win + R
to open the Run dialog. - Type
taskschd.msc
and press Enter to open Task Scheduler.
- Press
Create a Basic Task:
- In the Task Scheduler window, click on
Create Basic Task
in the Actions pane. - Enter a name and description for the task, then click
Next
.
- In the Task Scheduler window, click on
Set the Trigger:
- Choose when you want the task to start (e.g., Daily, Weekly, One time).
- Set the specific details for the trigger (e.g., start date and time), then click
Next
.
Set the Action:
- Select
Start a program
and clickNext
.
- Select
Specify the Program to Run:
- In the
Program/script
field, enter the path to the Python executable. For example,C:\Python39\python.exe
(adjust the path according to your Python installation). - Below is an example on how to find the path of python in command prompt
- In the
Add arguments (optional)
field, enter the path to your Python script. For example,C:\path\to\your\script\example.py
. - Optionally, in the
Start in (optional)
field, enter the directory where your script is located. This can help if your script relies on relative paths. - Eg:
- Program/script:
C:\Python39\python.exe
- Add arguments (optional):
C:\Users\BKa\Desktop\Mail-Test.py
- Start in (optional):
C:\Users\BKa\Desktop
Finish the Task:
- Review the settings and click
Finish
.
- Review the settings and click
Optional Settings:
- You can further customize the task by right-clicking on the task in the Task Scheduler Library and selecting
Properties
. - In the
General
tab, you can configure the task to run with highest privileges if needed. - In the
Conditions
andSettings
tabs, you can adjust additional settings like stopping the task if it runs for too long, or running the task only if the computer is idle.
- You can further customize the task by right-clicking on the task in the Task Scheduler Library and selecting
By following these steps, your Python script will run automatically according to the schedule you set in Windows Task Scheduler.