Windows Command Prompt Task Scheduling
last modified July 14, 2025
Task scheduling in Windows allows automated execution of programs or scripts. The schtasks command provides this functionality through Command Prompt. Scheduled tasks can run at specific times, on system events, or periodically. This enables automation of maintenance, backups, and other repetitive tasks. Proper task scheduling reduces manual work and ensures timely execution.
The Windows Task Scheduler service manages all scheduled tasks. Tasks can run under different user accounts with various security contexts. Tasks support triggers, actions, conditions, and settings for flexible automation. The schtasks command offers full control over task scheduling from command line. This is essential for scripting and remote administration.
Tasks can be created to run programs, scripts, or send emails. They support daily, weekly, monthly, or one-time schedules. Tasks can also trigger on system startup, user login, or specific events. Advanced options include running only when idle or on AC power. Error handling and retry options make tasks robust.
This tutorial covers schtasks command usage with practical examples. We'll create, modify, run, and delete scheduled tasks. By the end, you'll be able to automate various system tasks efficiently. These skills are valuable for system administrators and power users.
Basic Task Scheduling Concepts
Before diving into examples, let's define key task scheduling concepts. Understanding these will help you create effective scheduled tasks.
A trigger specifies when a task should run. Common triggers include specific times, intervals, or system events. Multiple triggers can be combined in a single task. Triggers determine the task's schedule and activation conditions.
The action defines what the task will execute. This is typically a program, script, or email message. Actions specify the executable and its arguments. A task can contain multiple actions that run sequentially.
Conditions provide additional criteria for task execution. These include idle state, power status, or network availability. Conditions help prevent tasks from running at inappropriate times. They work alongside triggers to control execution.
Settings control task behavior beyond scheduling. These include retry attempts, execution time limits, and failure actions. Settings help manage how tasks run and handle problems. They ensure reliable task execution.
Creating a Daily Backup Task
This example creates a daily task to run a backup script. The task will execute every day at 2:00 AM.
@echo off schtasks /create /tn "DailyBackup" /tr "C:\scripts\backup.bat" /sc daily /st 02:00 /ru SYSTEM
This command creates a task named "DailyBackup" that runs backup.bat daily. The task runs under the SYSTEM account for maximum privileges.
schtasks /create
Initiates creation of a new scheduled task. All task creation commands start with this base command.
/tn "DailyBackup"
Specifies the task name as "DailyBackup". Task names should be descriptive and unique. They identify tasks in listings.
/tr "C:\scripts\backup.bat"
Defines the task action - running backup.bat. The /tr parameter specifies the program or script to execute.
/sc daily /st 02:00
Sets a daily schedule (/sc daily) starting at 2:00 AM (/st 02:00). Time uses 24-hour format. This creates a recurring daily trigger.
/ru SYSTEM
Runs the task under the SYSTEM account. This provides elevated privileges without storing user credentials.
C:\>create_daily_backup.bat SUCCESS: The scheduled task "DailyBackup" has successfully been created.
Successful execution returns a confirmation message. The task now appears in Task Scheduler and will run daily.
Scheduling a Weekly Maintenance Task
This example schedules a weekly maintenance script to run every Sunday at 3:00 AM.
@echo off schtasks /create /tn "WeeklyMaintenance" /tr "C:\scripts\maintenance.bat" /sc weekly /d SUN /st 03:00 /ru "DOMAIN\Admin" /rp "P@ssw0rd"
This creates a task that runs maintenance.bat weekly on Sundays. The task uses domain admin credentials for required permissions.
/sc weekly /d SUN
Sets a weekly schedule (/sc weekly) running on Sundays (/d SUN). Day codes are MON,TUE,WED,THU,FRI,SAT,SUN.
/ru "DOMAIN\Admin" /rp "P@ssw0rd"
Specifies the run-as account and password. For domain accounts, use DOMAIN\Username format. Local accounts use .\Username.
/st 03:00
Sets the start time to 3:00 AM. Combine with /sc and /d for complete scheduling control.
C:\>weekly_maintenance.bat SUCCESS: The scheduled task "WeeklyMaintenance" has successfully been created.
The task is created and will run weekly. Verify in Task Scheduler for proper configuration.
Creating a Task That Runs on System Startup
This example creates a task that runs automatically when the system starts. Useful for monitoring or service scripts.
@echo off schtasks /create /tn "StartupMonitor" /tr "C:\scripts\monitor.exe" /sc onstart /delay 0005:00
This creates a task that runs monitor.exe at system startup. The task waits 5 minutes after startup before executing.
/sc onstart
Configures the task to run on system startup. This trigger activates when Windows starts, before user login.
/delay 0005:00
Delays task execution by 5 minutes after the trigger. Format is HHMM:SS. Useful to let system stabilize before running tasks.
C:\>startup_task.bat SUCCESS: The scheduled task "StartupMonitor" has successfully been created.
The task will automatically run after each system reboot. No manual intervention is required.
Scheduling a Monthly Task with Multiple Triggers
This example creates a task with multiple triggers - running monthly and on the last day of month.
@echo off schtasks /create /tn "MonthlyReport" /tr "C:\scripts\report.bat" /sc monthly /mo 1 /d 1 /st 23:00 schtasks /change /tn "MonthlyReport" /add /sc monthly /mo LASTDAY /st 23:00
Creates a task that runs on the 1st day of month and last day of month. Both triggers execute at 11:00 PM.
/sc monthly /mo 1 /d 1
Sets monthly schedule (/sc monthly), every 1 month (/mo 1), on the 1st day (/d 1). Creates the first trigger.
schtasks /change /tn "MonthlyReport" /add /sc monthly /mo LASTDAY
Adds a second trigger to the existing task. This one runs on the last day of month (LASTDAY).
/st 23:00
Both triggers use the same start time (11:00 PM). Time is specified once per trigger.
C:\>monthly_task.bat SUCCESS: The scheduled task "MonthlyReport" has successfully been created. SUCCESS: The parameters of scheduled task "MonthlyReport" have been changed.
The task now has two triggers visible in Task Scheduler. It will run twice monthly as configured.
Creating a Task That Runs Every 15 Minutes
This example schedules a task to run every 15 minutes between work hours.
@echo off schtasks /create /tn "FrequentCheck" /tr "C:\scripts\check_status.bat" /sc minute /mo 15 /st 08:00 /et 17:00 /k
Creates a task that runs check_status.bat every 15 minutes from 8 AM to 5 PM. The task stops if still running at end time.
/sc minute /mo 15
Sets a schedule to run every 15 minutes (/mo 15). The /sc minute specifies minute-based recurrence.
/st 08:00 /et 17:00
Defines the active period from 8:00 AM to 5:00 PM. The task only runs within this time window.
/k
Terminates the task if still running at end time. Ensures tasks don't overlap or run indefinitely.
C:\>frequent_task.bat SUCCESS: The scheduled task "FrequentCheck" has successfully been created.
The task will run every 15 minutes during business hours. Verify the schedule in Task Scheduler.
Listing and Managing Scheduled Tasks
After creating tasks, you may need to list, run, or delete them. These commands help manage existing tasks.
@echo off echo Listing all tasks: schtasks /query /fo list echo. echo Running task immediately: schtasks /run /tn "DailyBackup" echo. echo Deleting task: schtasks /delete /tn "OldTask" /f
This script demonstrates task management commands: listing, running, and deleting tasks. The /f switch forces deletion without confirmation.
schtasks /query /fo list
Lists all scheduled tasks in detailed list format. The /fo parameter controls output format (TABLE,LIST,CSV).
schtasks /run /tn "DailyBackup"
Runs the "DailyBackup" task immediately, regardless of schedule. Useful for testing or manual triggering.
schtasks /delete /tn "OldTask" /f
Deletes the "OldTask" task without confirmation (/f). Exercise caution as this cannot be undone.
C:\>manage_tasks.bat Listing all tasks: Folder: \ TaskName: \DailyBackup Status: Ready ... Running task immediately: SUCCESS: Attempted to run the scheduled task "DailyBackup". Deleting task: SUCCESS: The scheduled task "OldTask" was successfully deleted.
Output shows task details, execution confirmation, and deletion success. Actual output varies by system.
Source
Microsoft schtasks Documentation
In this article, we have covered task scheduling using Windows Command Prompt. These techniques enable powerful automation of system administration tasks.