SCHTASKS - CMD


Overview

The SCHTASKS command in Windows Command-Line is a utility for scheduling, creating, deleting, configuring, and managing tasks in the Task Scheduler. It enables users to automate the running of scripts, programs, or commands at pre-configured times or events. This tool is especially useful in administration for automating maintenance tasks and for users who want to schedule regular backups or updates.

Syntax

The basic syntax for SCHTASKS is:

SCHTASKS /parameter [arguments]

Creating Tasks

To create a scheduled task:

SCHTASKS /Create /SC schedule_type /TN task_name /TR task_run [/ST start_time] [/RI interval] [/ET end_time] [/SD start_date] [/ED end_date] [/MO modifier] ...

Deleting Tasks

To delete a scheduled task:

SCHTASKS /Delete /TN task_name [/F]

Running Tasks

To run a scheduled task immediately:

SCHTASKS /Run /TN task_name

Ending Tasks

To stop a currently running task:

SCHTASKS /End /TN task_name

Changing Tasks

To change properties of a task:

SCHTASKS /Change /TN task_name [options to change]

Querying Tasks

To display information about scheduled tasks:

SCHTASKS /Query [/TN task_name] [/FO format] [/NH]

Options/Flags

  • /Create: Creates a new scheduled task.
  • /Delete: Deletes the task(s).
  • /Run: Runs the task immediately.
  • /End: Stops the currently running task.
  • /Change: Changes the properties of an existing task.
  • /Query: Displays information about scheduled tasks.
  • /SC: Required for /Create. Defines the schedule frequency (e.g., MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON).
  • /TN: Specifies the name of the task.
  • /TR: Defines the path of the program or script that the task will run.
  • /MO: Modifier, changes depending on /SC (e.g., every 2 weeks or every 3 days).
  • /ST: Start time (24-hour clock, HH:MM format).
  • /RI: The repetition interval in minutes.
  • /ET: Ends the task at a specific time.
  • /SD: The start date of the task.
  • /ED: The end date of the task.
  • /F: Forcefully deletes the task without confirmation.

Examples

Create a daily cleanup task to run at 3:00 PM every day:

SCHTASKS /Create /SC DAILY /TN "Daily Cleanup" /TR "C:\Path\to\script.bat" /ST 15:00

Delete a task named ‘Daily Backup’ without confirmation:

SCHTASKS /Delete /TN "Daily Backup" /F

Run a task named ‘Data Sync’ right away:

SCHTASKS /Run /TN "Data Sync"

Common Issues

  • Permission Errors: Ensure you have the necessary administrative privileges.
  • Syntax Errors: Double-check command syntax and parameters used.
  • Scheduling Conflicts: Make sure the start time doesn’t overlap with another task.

Integration

Combine SCHTASKS with powershell scripts to handle complex scheduling:

SCHTASKS /Create /SC WEEKLY /TN "Weekly Report" /TR "powershell.exe -File C:\Scripts\report.ps1" /ST 09:00 /SD 01/01/2021

In this example, the task scheduler runs a PowerShell script every week.

  • AT: Older command similar to SCHTASKS but with less functionality.
  • PowerShell Scheduled Tasks Cmdlets: More granular task scheduling options available in PowerShell.

For further reading and more detailed information, refer to the official Microsoft documentation on SCHTASKS.