XP Pro: Schedule a program to run once at a specific time using schtasks

Home -> Windows

15421 views

From the computer of: qmchenry (339 recipes)
Created: May 02, 2004


Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

Windows XP Professional has a command line utility that allows users to schedule the execution of tasks. The schtasks utility has a wide variety of options. This recipe provides a simple example of scheduling a task to run once in the future.

The minimum parameters required to run a task once are /sc (schedule), /tr (task to run), /st (start time), and /tn (unique task name). This syntax will run the task as the current user. To run the defrag program on the C: drive at 11 PM, use this command:

schtasks /create /sc once /st 23:00:00 /tn cdefrag /tr "defrag c:"


The schedule (/sc once) indicates that the task will only be executed once. The start time (/st 23:00:00) determines the time (HH:MM:SS) that the task will start in the 24 hour format. The task name (/th cdefrag) must be a unique name that can be used to reference the scheduled task later. The task to run (/tr "defrag c:") specifies the command and parameters to run. Enclosing the task to run in quotes is required for tasks with options.

When you run the command above, it will tell you the user the task will run under (the current user) and will prompt for that user's password. It is possible to place the password in the command (using /rp password) although to do so may be a security risk -- use at your own risk.

If you want to run the task as another user, specify the username with the /ru username command option.

By default, the task will execute within the next 24 hours at the next occurance of the start time. To run the command at the speficied time on a different date, use the /sd mm/dd/yyyy option.

To view the scheduled events, just run schtasks with no options.

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  RunAs a User on the Network
  Vista: Associate a File Type with a Specific Program
  95/98/ME/XP: Adjust Amount of CPU Resources a DOS Program Receives
  XP/2000: configure client sntp time protocol settings
  Outlook 2003: How To Give Your Email Message an Expiration Date
  Vista: Defrag (Defragment) Drive
  XP: Prevent Program from Appearing in the Frequently Used Program List
  Windows: How to Quit or Exit a Frozen, Locked-Up, Nonresponding Program
  Getting an Older Program to Run on Windows XP
  XP Pro and Vista: List active Windows programs from command line with tasklist

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.