9.15 Automating Scripts with Scheduled Tasks

The Scheduled Tasks feature is fairly simple, allowing you to schedule any program or more importantly in the context of this chapter any script.

What's nice about the Scheduled Tasks feature is that it's actually a technology that is somewhat well integrated into the operating system. Any application can create a schedule for itself, and you can plainly see those that are in effect simply by opening the Scheduled Tasks folder. For the more forgetful among us, you can use it to schedule Disk Defragmenter to run once a month, Backup to run once a week, or Windows Update to check for new updates every morning.

The Scheduled Tasks feature also has its pitfalls. The Add Scheduled Task tool is cumbersome and very limited. It's also a rather passive service, and while that's an aspect I like, at least idealistically, it means that tasks can very easily be missed. Any scheduled tasks will not be performed if you've selected the Stop Using Task Scheduler option (in the Advanced menu), if your computer is turned off, if Windows isn't running, or if your portable computer is running off its battery. These may be obvious, but they can be easy to forget, and Windows will only tell you if you missed any tasks if you manually enable the Notify Me of Missed Tasks option.

There are several ways to create a new scheduled task, the most obvious of which is to double-click the Add Scheduled Task icon in the Scheduled Tasks folder. The overly verbose wizard should then walk you through the process of creating a new task. When the wizard prompts you to select a program (it just displays a list of all the applications listed in your Start Menu), click Browse, select an existing script or other application on your hard disk, and click OK when you're done. At this point, I recommend just clicking Next repeatedly here until the wizard is finished. Then right-click on the new task, and select Properties to configure the task with a more suitable and convenient tabbed interface.

Fortunately, there is a shortcut you can use to bypass the wizard entirely: just go to File figs/u2192.gif New figs/u2192.gif Scheduled Task, or right-click an empty area of the Scheduled Tasks folder, and select New and then Scheduled Task. Then, right-click the new task, and select Properties.

Finally, you can create a new task on the fly from the command prompt (or the Address Bar). Use the at command, like this:

at 11:15 /interactive c:\scripts\myscript.vbs

Naturally, you'll want to replace 11:15 with the time you actually want the task to run, and replace c:\scripts\myscript.vbs with the full path and filename of the application or script you wish to schedule. You can also use the /every option to specify a repeating day or date, or the /next option to specify only a single day:

at 15:45 /interactive /every:tuesday,thursday c:\scripts\myscript.vbs at 15:45 /interactive /next:saturday c:\scripts\myscript.vbs

Type at /? at the command prompt for more options, or see Windows XP in a Nutshell (O'Reilly) for full documentation.

One thing to note is the two Power Management settings in the Settings tab of the task's Properties dialog box. By default, tasks won't be run if your computer is running on batteries a setting you may want to change if you need the task performed regardless of your computer's power source.

The use of a scheduler opens up some interesting possibilities. Scheduling helps with repetitive chores, such as running Disk Defragmenter or synchronizing network files; it also helps by taking care of things you may not remember to do yourself, such as backing up or sending an email to your grandmother on her birthday. See the following topic for more ideas.



Windows XP Annoyances
Fixing Windows XP Annoyances
ISBN: 0596100531
EAN: 2147483647
Year: 2005
Pages: 78
Authors: David A. Karp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net