Managing Scheduled Tasks

Microsoft® Windows® 2000 Scripting Guide

Scheduled tasks (also referred to as scheduled jobs) provide a way to schedule activities to run on a computer at specific days and at specific times. Because scheduled tasks are run by the Task Scheduler service, these tasks can be run regardless of whether a user is logged on to the computer.

Scheduled tasks are useful in several ways:

  • They help ensure that important activities are carried out on a regular basis.

    If you need to run an inventory script every week, you can schedule the script to run automatically every Friday instead of sending out weekly reminders to users and relying on them to manually run the script.

  • They help minimize disruptions to users and to the network.

    A backup program can require a considerable amount of processing power on a computer and use a considerable amount of network bandwidth. To minimize the impact of this program, you can schedule it to run late at night, when network traffic is at a minimum. Scheduled tasks will run even if no one is logged on to the computer.

  • They are persistent.

    When you create a scheduled task, you create a file stored in a special folder (systemroot\Tasks). These files are not deleted unless you specifically delete them. As a result, scheduled tasks persist regardless of how many times a computer is restarted.

Comparing Win32_ScheduledJobs and the Task Scheduler

Working with scheduled tasks is complicated by the fact that Windows 2000 includes two sets of task-scheduling APIs:

  • Task Scheduler APIs, used by the Scheduled Tasks wizard. These tasks cannot be scripted.

  • AT APIs, used by At.exe. These tasks can be scripted using the WMI class Win32_ScheduledJob.

A comparison of the two kinds of task-scheduling APIs is shown in Table 17.12.

Table 17.12 Task-Scheduling APIs

Task Scheduler APIs


Tasks can run under any valid user account; you specify the account name and the password when you create the task.

Tasks must run under the same account as the scheduler service. By default, this is the LocalSystem account, although you can configure the service to run under a different account.

Tasks can be scheduled to start at logon, at system startup, or whenever the system is idle.

Tasks can be run only at specific times (for example, 3:00 P.M. every Tuesday).

Task durations can be specified. For example, you can schedule a task to run for one hour and then stop.

This is useful for monitoring scripts: they can be scheduled to run for a specified amount of time, and then be shut down.

Task durations cannot be specified. To run a task for a specific amount of time (for example, one hour) you must include code within the task itself that will terminate the script at the appointed time.

Tasks can be given any file name (for example, Compact Database.job).

Tasks are automatically assigned a name that uses the format Atx.job, with x representing consecutive integers (At1.job, At2.job, At3.job, and so forth).

Tasks created using the Task Scheduler APIs are invisible to the Win32_ScheduledJob class.

Tasks created using the AT APIs can be opened and modified using Scheduled Tasks.

You cannot modify a task created using the AT APIs. Instead, you need to delete the task and then create a new one in its place. For example, to change a task scheduled to run on every Tuesday so that it instead runs every Friday, you need to delete the Tuesday task and then re-create the task, making sure that it is scheduled to run on Fridays.

You can use Scheduled Tasks to modify a task created by using the AT APIs. If you do this, however, that task will no longer be available to the Win32_ScheduledJob class. The task will still run, but you will not be able to enumerate or delete it by using WMI because the Scheduled Tasks tool adds properties to the job that are not supported by the AT APIs. The task will also "disappear" from WMI if you give it a name with any format other than Atx.job.