Schedule recurring tasks in Windows
Use Task Scheduler or schtasks to run scripts on a schedule, with an explicit interpreter, task account, and working directory.
Windows does not ship with Unix cron. Its native equivalent is Task Scheduler: define a trigger, an action, and the account that runs the task. Use schtasks for command-line administration, or run Linux cron inside a suitably configured WSL distribution.
Use Task Scheduler
- Search for Task Scheduler, or run
taskschd.msc. - Choose Create Task for the full set of options.
- Under General, name the task and select its account. For unattended work, configure Run whether user is logged on or not when supported by that account. Enable Run with highest privileges only if the task requires elevation.
- Under Triggers, create a daily, weekly, or monthly trigger. Use the repeat interval for frequent execution, such as every five minutes.
- Under Actions, choose Start a program. For Python, select the actual interpreter, such as
C:\Python312\python.exe, and put the script path in its arguments. For Windows PowerShell, usepowershell.exewith-NoProfile -File C:\jobs\backup.ps1. - Set Start in if the script relies on a working directory. Review power conditions, overlapping-instance behavior, and failure retries.
Run the saved task manually first, then check Last Run Result and the script's own output. Across several hosts, record the host, task name, start/completion times, and exit code, then collect the records with DataKit.
Use schtasks
The following examples use cmd.exe syntax:
:: Run a batch script daily at 02:30.
schtasks /create /tn "NightlyBackup" /tr "C:\jobs\backup.bat" /sc daily /st 02:30
:: Run a PowerShell script every ten minutes.
schtasks /create /tn "Poll" /tr "powershell.exe -NoProfile -File C:\jobs\poll.ps1" /sc minute /mo 10
:: Inspect or delete the named task.
schtasks /query /tn "NightlyBackup"
schtasks /delete /tn "NightlyBackup"
A .ps1 file is not an executable program for the action; launch PowerShell explicitly. Paths containing spaces need appropriate quoting. Configure the task's account and credentials for the intended execution context rather than assuming the default account can run unattended or access network resources.
Run cron in WSL
Install and start the cron service inside the Linux distribution, then use crontab -e. WSL must remain running for that scheduler to execute. Do not assume installing a crontab starts the daemon or guarantees unattended Windows-host execution. Native Task Scheduler is often easier to operate for host-level jobs.
FAQ
Why did the task not run at the expected time?
Check whether the machine was asleep, battery conditions prevented execution, the task required a logged-in user, or the action failed because of its working directory or account permissions. Review the trigger's settings for missed starts as well.
How do I use SYSTEM or a service account?
Choose Change User or Group under General, then configure the appropriate logon and privilege options. SYSTEM's local privileges do not mean it has an arbitrary user's network credentials.
What if PowerShell blocks the script?
Check the script's source, signing requirements, and effective execution policy. An approved process-scoped -ExecutionPolicy setting may be used where policy permits, but it does not override Group Policy. Do not make a permanent machine-wide policy change merely to get a task running.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan