By Ed Bott, Carl Siechert, and Craig Stinson(Adapted from Windows Vista Inside Out © 2007 Microsoft Corporation. To learn more about this book, visit the Microsoft Learning website.)
PROBABLY THE MOST IMPORTANT AUTOMATION TOOL at your disposal is task scheduler, which is significantly more powerful and easier to use in the Windows Vista operating system than it was in Windows XP.
This column introduces you to how task scheduler can be used to set up automated routines to be triggered by events or by a schedule that you specify. Task scheduler requires no programming expertise. The information that follows includes: using Windows Vista Task Scheduler, creating a task, setting up a task trigger or triggers, and setting up a task action or actions.
If you've used Scheduled Tasks in Windows XP, you'll be pleased by the changes in Windows Vista. To begin with, the user interface to the task scheduler has been implemented as a Microsoft Management Console (MMC) snap-in, giving you access to more information about the properties, status, and run history of your tasks (and those that the operating system and your programs have established for you). For more information about MMC, see What is the Microsoft Management Console (MMC)?
Second, the Scheduled Tasks snap-in has been neatly integrated with the Event Viewer snap-in, making it easy for you to use events (for example, an application crash or a disk-full error) as triggers for tasks. For more information about the Event Viewer snap-in, see Open Event Viewer.
Third, and most important, Windows Vista Task Scheduler supports a much more extensive set of triggering and scheduling options. Now, in addition to running programs or scripts at specified times, you can start actions when the computer has been idle for a specified time period, when particular users log on or log off, and so on. You can use these (and other) triggers to send e-mail messages or to display a message window, as well as to run programs or scripts.
If you have an Administrative Tools folder on your Start menu, you can find Task Scheduler there. Or, if you're handy at the keyboard, simply press Windows logo key+R, and then type taskschd.msc in the Run dialog box. However you issue the command, you'll need to answer a User Account Control (UAC) dialog box prompt before the Task Scheduler snap-in appears.
The following illustration shows Task Scheduler in its default layout. As you can see, the window is divided vertically into three panes—a console tree on the left, an Actions pane on the right, and various informative areas in the center pane. The console tree shows you which computer you're working with (the local computer or a network computer to which you have connected) and provides a folder tree of currently defined tasks. You can create your own folders here to organize the tasks that you create yourself, or you can add new tasks to existing folders.
The Actions pane provides a menu of things you can do. With rare (and probably unintended) exceptions, items here are also available on the menus at the top of the window, so if you're feeling cramped in the center pane, you might consider hiding the Actions pane. (To do this, click View, click Customize, and then clear the Action pane check box.)
In the center pane, initially, you'll see an Overview of Task Scheduler message (this is a static bit of text; once you've read it, you can hide it by clicking the collapse arrow at the right), a status report (in the Task Status area) of all tasks that have run (or were scheduled to run) during some period of time (by default, the most recent 24 hours), and a summary of all the currently enabled tasks (in the Active Tasks area). Entries in the Task Status list have outline controls; click an item's plus sign to see more details.
The Task Status and Active Tasks areas are not updated automatically. To get the latest information, click Refresh (at the bottom of the screen, in the Actions pane, or on the Action menu).
If this is your first visit to Task Scheduler, you might be surprised by the number of active tasks that Windows and your programs have already established. For example, if you use the Windows Vista backup program to perform regular, full, and incremental backups, you'll find some backup-related items in the Active Tasks list. Unless you or someone else has disabled automatic disk defragmentation, there will be an item in the list. If you rely on Windows Calendar or another program to remind you of appointments or task deadlines, chances are that functionality will be represented in the Active Tasks list.
To see what tasks managed by Task Scheduler are currently running, click Display All Running Tasks in the Actions pane. (If you're looking for this command on the Action menu, be sure that the top node in the console tree is selected.) Review the tasks, and then click Close.
To satisfy your curiosity about what an active task does and how it has been set up, you'll need to locate it in the console tree. Expand the console tree entries as needed, and then browse to an item of interest. The console tree entries are virtual folders, each of which can contain subfolders or one or more tasks.
When you select a folder in the console tree, the center pane in Task Scheduler splits into two panes. The upper pane lists all of the tasks stored in the selected folder. The lower pane, meanwhile, shows tabbed pages of the properties of the current task. The following illustration shows the WindowsBackup folder selected in the console tree, the AutomaticBackup task selected in the upper pane, and the General properties page for the AutomaticBackup task in the lower pane. (The Actions pane is hidden in this illustration.)
The tabbed property pages that appear in the lower pane of the Task Scheduler snap-in (for example, see the previous illustration) are read-only. To edit the properties associated with a task, right-click the task name in the upper pane, and then click Properties. (Or, you can double-click the task name in the upper pane.) Either way, this opens a dialog box with read/write properties in a separate window.
With the exception of the History tab, the tabbed property pages in the lower pane are simply a read-only version of the Create Task dialog box, one of the tools you can use to create a new task. We'll explore that dialog box in some detail, later in this column. The History tab allows you to see exactly how, whether, and when a task has run. The following illustration shows the History tab for the AutomaticBackup task.
When you click the History tab, the relevant part of the Event Viewer snap-in snaps in, showing you all of the recent events relating to the selected task. This is exactly what you would see if you ran Evntvwr.msc, navigated in the console tree to Applications and Services Logs\Microsoft\Windows\TaskScheduler\Operational, and then filtered the resulting event log to list events relating to the selected task.
Obviously, if you want this information, it’s quicker to find it in the Task Scheduler console than in the Event Viewer console. If a task you’ve set up is not getting triggered when you expect it to or is not running successfully when it should, you can double-click the appropriate event entry and read whatever details the event log has to offer.
You can set up tasks on your own computer or on any other computer to which you have access. If you're administering a remote computer, start by selecting the top item in the console tree, the one that says Task Scheduler (Local), if you haven't yet connected to a remote computer. Then, in the Actions pane (or from the Action menu), click Connect to Another Computer. To begin creating a new task, click the folder in the console tree where you want the task to reside. If you need to create a new folder for this purpose, right-click the parent folder under which you want the new folder to appear in the console tree, and then click New Folder. Type a name for the new folder, and then click OK.
You can create a new task in the Scheduled Tasks snap-in either by using the Create Basic Task Wizard or by filling out the Create Task dialog box. The wizard, which you start by clicking Create Basic Task (in the Actions pane or from the Action menu), is ideal for time-triggered tasks involving a single action. It's also fine for setting up a task to run when you log on or when Windows starts. For a more complex task definition, you'll need to work through the Create Task dialog box. Click the folder (in the console tree) where you want the task to appear, and then click Create Task (in the Actions pane or from the Action menu). The following illustration shows the General tab of the Create Task dialog box.
The one required entry on the General tab is a name for the task; everything else is optional. The task author is you (you can't change that), and, unless you specify otherwise, the task will run in your own security context. If you want the task to run in the security context of a different user or group, click Change User or Group, and then select the options you want.
The circumstance under which you're most likely to need to change the security context is if you're setting up tasks to run on another computer. If you intend to run programs with which another user can interact, you should run those in the other user's security context. If you run them in your own security context, the tasks will run noninteractively (that is, the user will not see them).
Regardless of which user's security context the task is to run in, you have the option of allowing the task to run whether or not that user is logged on. If you select Run whether user is logged on or not, you will be prompted for the user's password when you finish creating the task. If you don't happen to have that password, you can select Do not store password. As the text beside this check box indicates, the task will have access to local computer resources only.
Tasks can be triggered in the following ways:
On a schedule
On an event
At task creation or modification
On connection to a user session
On disconnect from a user session
On workstation lock
On workstation unlock
You can establish zero, one, or several triggers for a task. If you don't set any triggers, you can still run the task on demand (unless you clear the Allow task to be run on demand check box on the Settings tab of the Create Task dialog box). This gives you a way to test a new task before committing it to a schedule, for example. If you set multiple triggers, the task runs when any one of the triggers occurs.
To set up a trigger, click the Triggers tab in the Create Task dialog box, and then click New. In the New Trigger dialog box (see the following illustration), select the type of trigger you want from the Begin the task menu.
Note the Advanced settings options at the bottom of the dialog box (see the previous illustration). These options, which let you establish delay, repeat, and expiration parameters (among other things), are not so easy to find when you're reviewing a task that you or someone else already created. They don't appear in the read-only version of task properties. And if you open the read/write version of the properties by opening the Create Task dialog box, you'll need to select a trigger (on the Triggers tab), and then click Edit to see or change the advanced options.
Other than the task name (which you supply on the General tab of the Create Task dialog box), the only other task parameter you must provide is the action or actions the task is supposed to perform. To do this, in the Create Task dialog box, click the Actions tab, click New, and then select the options you want.
Three types of actions are possible:
Start a program
Send an e-mail message
Display an e-mail message
For each type of action, you may specify one or several actions to occur. Multiple actions are carried out sequentially, with each new action beginning when the previous one has completed.
If you select the Start a program action, it can be applied to anything that Windows can implement—a Windows program, a batch program or script, a document associated with a program, or a shortcut. You can use the Browse button to simplify entry of long path specifications, you can add arguments for your executable in the Add arguments box, and you can specify a start-in folder for the executable. If your program needs elevated privileges to run successfully, be sure that you have selected Run with highest privileges on the General tab of the Create Task dialog box.
If you select the Send an e-mail action, Task Scheduler requires you to provide the address of your outbound (SMTP) server.
If you select the Display a message action, the dialog box that appears provides fields for the message title and message text.
The Send an e-mail and Display a message actions are not available for tasks that are set to run on Windows XP, Windows 2000, or Windows Server 2003.
About the authors
Ed Bott is an award-winning journalist and one of the most recognized voices in the computing world. He’s been writing about MicrosoftWindows and Microsoft Office for more than 15 years and is the author of nearly two dozen books.
Carl Siechert specializes in implementing and documenting operating system technologies. He has coauthored several Windows-related books including the popular MicrosoftWindows XP Inside Out, Second Edition with Ed Bott and Craig Stinson.
Craig Stinson is a journalist and author. He has written or coauthored more than 20 books including MicrosoftWindows XP Inside Out, Deluxe Edition, and Microsoft OfficeExcel 2007 Inside Out.
Have a comment for the authors? Enter your feedback using the tool below. (You'll see the comment box after you click one of the buttons.) Note that although the authors will read your feedback, personal replies are not possible due to the volume of feedback received.