Schedule Python Excel, PDF and email reports automatically on Windows using Task Scheduler or schtasks. Run a Python script or packaged EXE on a daily schedule.
Architecture: Schedule Reports Automatically
Schedule Reports Automatically
Trigger
Daily / shift / startup schedule
08:00 dailyTask Scheduler
Windows scheduling engine
TaskPython / EXE
Launch report program
python report.pySQL Server
Read latest plant data
SELECT ...Report
Generate Excel/PDF
D:\SQF_ReportsLog / Email
Record result or distribute
report.log1. Prepare a non-interactive report program
Scheduled programs should not depend on manual input boxes. Put paths, database settings and report rules in configuration or validated constants.
2. Test the exact command manually
cd /d D:\SQF_Report
.venv\Scripts\python.exe report.pyUse the same executable and working directory that the scheduled task will use.
3. Task Scheduler fields
| Field | Example |
|---|---|
| Program/script | D:\SQF_Report\.venv\Scripts\python.exe |
| Add arguments | D:\SQF_Report\report.py |
| Start in | D:\SQF_Report |
4. Create a task with schtasks
schtasks /Create /SC DAILY /TN "SQF Daily Report" ^ /TR "D:\SQF_Report\SQF_Report.exe" /ST 08:005. Use an absolute output folder
from pathlib import Path
OUTPUT = Path(r"D:\SQF_Reports")
OUTPUT.mkdir(parents=True, exist_ok=True)6. Scheduled-job checklist
- Task account has SQL and folder permissions
- Start-in folder is correct
- ODBC driver exists on the machine
- Logs record success/failure
- Test task manually before production scheduling
Frequently Asked Questions
Can Task Scheduler run a Python script?
Yes. Configure the Python interpreter as the program and the script path as an argument, or schedule a packaged EXE.
Why does a script work manually but fail when scheduled?
Common causes include a different working directory, account permissions, missing environment variables or using another Python environment.
Should scheduled reports write logs?
Yes. Logs are important because the task may run unattended.
