Two Minute Drill: The Schtasks command

Two Minute Drill: The Schtasks command

  • Comments 10
  • Likes

Hello again AskPerf! Blake here to show you a not-so-utilized command line tool called Schtasks. The Schtasks command enables an administrator to create, delete, query, change, run, and end Scheduled Tasks on your local or remote system. For those command line junkies who need an easy way to manage their Scheduled Tasks, this is the tool for you. Let’s check out its options and some examples.

When you type “Schtasks /?” from a command prompt, the following appears:

 

Microsoft Windows [Version 6.1.7600]

Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

 

C:\>schtasks /?

SCHTASKS /parameter [arguments]

Description:

   Enables an administrator to create, delete, query, change, run and end

   scheduled tasks on a local or remote system.

Parameter List:

   /Create Creates a new scheduled task.

   /Delete Deletes the scheduled task(s).

   /Query Displays all scheduled tasks.

   /Change Changes the properties of scheduled task.

   /Run Runs the scheduled task on demand.

   /End Stops the currently running scheduled task.

   /ShowSid Shows the security identifier corresponding to a scheduled task name.

   /? Displays this help message.

Examples:

   SCHTASKS

   SCHTASKS /?

   SCHTASKS /Run /?

   SCHTASKS /End /?

   SCHTASKS /Create /?

   SCHTASKS /Delete /?

   SCHTASKS /Query /?

   SCHTASKS /Change /?

   SCHTASKS /ShowSid /?

   SCHTASKS /?

 

Here are some quick examples:

 

Query a remote system to display its scheduled tasks:

.

C:\>schtasks /Query /S <MachineName>

Folder: /

TaskName                        Next Run Time          Status

=============================== ====================== ===============

Chkdsk                          4/6/2010 9:35:00 AM    Ready

Disk Cleanup                    4/5/2010 9:34:00 AM    Unknown

Disk Defragment                 4/1/2010 2:00:00 AM    Ready

.

      

Create a scheduled task locally that runs Notepad daily at 10:00AM:

.

C:\>Schtasks /Create /TN Notepad /TR notepad.exe /sc DAILY /ST 10:00 /RU administrator /RP password

SUCCESS: The scheduled task "Notepad" has successfully been created.

.

NOTE: When you use the /U & /P switches from a Vista+ machine to an 2000/XP/2003 machine, you will receive the following error: “ERROR: The request is not supported.”.  The feature to run Schtasks.exe under a specific username and password (/U /P) is not supported on legacy machines.

     

To start the above task then confirm that it is running, type this:

.

C:\>schtasks /Run /TN Notepad

SUCCESS: Attempted to run the scheduled task "Notepad".

C:\>schtasks /Query

Folder: \

TaskName                       Next Run Time          Status

============================== ====================== ===============

Notepad                        3/31/2010 10:00:00 AM  Running

.

    

Finally, to delete this scheduled task even though it is running, type this:

.

C:\>schtasks /Delete /TN Notepad /F

SUCCESS: The scheduled task "Notepad" was successfully deleted.

.

 

As you can see, this tool can be extremely useful at manipulating Scheduled Tasks from the command line, especially if you are trying to access remote machines over slow WAN links. We recommend that you play around with the many options Schtasks provides, and find the ones that work best for you. The links below have more information and examples. Until next time…

 

Additional Resources:

· Schtasks on XP

· How to use Schtasks.exe to Schedule Tasks in Windows Server 2003

· Schtasks on MSDN

· Schtasks on TechNet

 

-Blake Morrison

Share this post :


Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • A very useful command.

    I'm looking for more info on the  /EC (ChannelName) switch. This switch replaces the functionality of the EventTriggers command, which was well documented, but removed in Vista.

    Also, when you post cmd window images, could you possibly right-click the window and Select All, so that the image appears black text on white background? Much nicer on print toner.

  • When scheduling a task from Win7 to W2K3 as the system account we get error " ERROR: Unable to establish existence of the account specified. ". The solution is to use the /v1 switch. Now why the schtasks.exe developers couldn't just recognize that the target system was W2K3 and automatically use the /v1 logic without forcing the user to add the switch is beyond me. Maybe MS can force all of their software vendors to support W2K8 so they can upgrade every server, but in the real world we have to live with legacy OS's.

    And I'm still looking for the schtasks equivalent of "run this task next friday" that we could do with "at 10:00 /next:friday foo.exe"

  • This little nugget:

    "NOTE: When you use the /U & /P switches from a Vista+ machine to an 2000/XP/2003 machine, you will receive the following error: “ERROR: The request is not supported.”.  The feature to run Schtasks.exe under a specific username and password (/U /P) is not supported on legacy machines."

    saved me a BUNCH of time.  Thanks!  

    That has to be a candidate for the "meaningless  message of the week" award.

  • I had to use the /V1 switch with schtasks.exe to remotely create a Task from a Windows 7 machine to a Windows 2008 R2 server that uses the credential switches (/S, /U , /P), it doesn't make sense I have to provide the switch when both environments shouldn't require a "pre-vista" hack...

  • How can I create a task in a special folder in the task scheduler library?

  • Thilo, try this:

    Schtasks /CREATE /XML notepad.xml /TN MyCustomFolder\Notepad

    This goes under the assumption that the “%windir%\System32\Tasks\MyCustomFolder” is present.

  • For Disaster Recovery purposes I need to backup and be able to restore all Scheduled Tasks (the machine is not restored from tape but actually rebuilt in a DR scenario).

    I am able to create an XML file of all scheduled task using this command...

    schtasks /Query /XML ONE>d:\backup\Tasks\schedtasksBackup.xml

    The problem is when I try to import the file on another box. How do I do it???

    I tried...

    schtasks /Create /XML d:\backup\Tasks\schedtasksBackup.xml

    ...but it tells me "Invalid syntax. Mandatory option 'tn' is missing." TN is the parm to specify a task name but I want them all restored. This is supposed to be an automated process and if I have to specify the task names the automation goes out the window.

    Thanks in advance for any help

  • Steven, you cannot do them in one big batch.  To use the /create /xml switches, /TN is required.

  • Hi,

    This article helo me a lot but not fully.

    I've created schedular using schtasks /create /tn name /tr notepad /sc daily /st 17:22:00 this command creates a schedular with "name" is created in scheduled folder but it's not executing at specified time..

    please help me in solving this

    Thanks,

    Sampath

  • Sampath compare what you did to the example and I think you will see why you got the results you are seeing.

    schtasks /create /tn name /tr notepad /sc daily /st 17:22:00

    Schtasks /Create /TN Notepad /TR notepad.exe /sc DAILY /ST 10:00 /RU administrator /RP password