5.7. Scheduling a Task


You want to schedule a task to run at a certain time or periodically.


Using a graphical user interface

  1. From the Control Panel, open the Scheduled Tasks applet.

  2. Double-click Add Scheduled Task.

  3. Click Next.

  4. Select the program you want to schedule to run.

  5. Type a name for the task, select the frequency in which to run it, and click Next.

  6. Enter the username and password of the user the task should run as and click Next.

  7. If you want to go back and modify any of the settings for the task, check the box beside Open advanced properties and click Finish.

Using a command-line interface

On Windows Server 2003 or Windows XP, you can use the schtasks.exe command to schedule a task. The following command creates a task to run weekly at 1:00 AM:

> schtasks /create /SC WEEKLY /TN "Disk Space Checker" /TR "c:\perl\bin\perl.exe 
c:\scripts\diskchecker.pl" /ST 01:00

On Windows 2000, you can use the at.exe command to schedule tasks. This command is functionally equivalent to the previous schtasks.exe example:

> at 01:00 /next:Sunday "c:\perl\bin\perl.exe c:\scripts\diskchecker.pl"


The at command is available on Windows Server 2003 as well, but you are better off using schtasks.

Using VBScript

' This code schedules a task to run every Sunday at 1:30AM. const MON = 1 const TUE = 2 const WED = 4 const THU = 8 const FRI = 16 const SAT = 32 const SUN = 64 ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strCommand = "c:\perl\bin\perl.exe c:\scripts\diskchecker.pl" strStartTime ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.