<B>Fred Langa</B> explains how to automate Windows XP tools and tasks that normally require manual intervention.

Fred Langa, Contributor

October 23, 2003

4 Min Read

Advanced Users: Extending The Process
Any command--any command at all--that you can enter manually can also be placed in a batch file and run from the Task Scheduler in the above fashion. But you also can gang many tasks into one batch file, which simplifies scheduling and also ensures that one task will finish before the next one starts. I find this latter feature the strongest argument in favor of using batch files for system maintenance. Yes, you can enter command-line arguments directly into Task Scheduler, but to prevent multiple tasks from overlapping or running simultaneously, you'd either have to depend on Task Scheduler's imperfect ability to detect whether or not another task has completed or use sheer guesswork in building your schedule to allow sufficient time for one task to end before another begins. A sequential batch file avoids these problems.

For an example of a more complex batch file, see "CleanXP.Bat" which uses some "hidden" features of XP's System Agent tool and the Disk Cleanup Wizard, along with a series of manual commands, to rid your hard drive of all manner of hard-to-remove Temp files, potentially hundreds of megabytes worth.

You can easily add the Defrag command (as explained earlier) to the end of the CleanXP batch file, letting your hard drive reorganize itself after each cleaning.

Or, you could go even further by using a single batch file to clean your drive, reorganize itself, and then back up your files.

This may not be obvious because XP's backup "Wizard" has its own built-in scheduling function; on its own, it won't integrate with other cleanup functions. But you can use the Backup Wizard to build the proper command string for an automated backup, and then lift and use that string in your own cleanup procedure.

Here's how: You first create a scheduled backup the normal way, using XP's Backup and Restore Wizard. Step through the complete process, including setting up all the time and date. It doesn't matter what schedule you choose, as long as you complete all the steps in the Wizard.

When you're done, open the Task Scheduler, find the backup task you just created, and right click on it, selecting Properties. A dialog box will then open. Copy the entire contents of the "Run" line in the Task tab. The Run line may be very, very long because it contains the complete command for triggering the backup you just created, including all options. Paste this line, exactly as-is, to the end of your cleanup/defrag batch file; it will run as the last step in the batch process, and perform a backup exactly as you set it up in the Backup and Restore Wizard. In fact, you can go back to Task Scheduler and delete or disable the Wizard-created backup, as it's now redundant.

[A note to Windows 2000 users: Alas, even though XP is built on Win2K technology, things are not always so simple: For example, to automate Backups in Win2K, you have to use a more complex and indirect command line to open the Management Console, and run the Defrag "snap-in" from there. See "Reader Defrag Tips And Info: Win2K" for more information.]

Limited Only By Your Imagination
XP can run any command-line program or standalone command this way, letting you build custom maintenance sequences that do exactly what you want, when you want, in the exact order you want. It's enormously powerful, surprisingly easy, and limited only by your ingenuity.

How do you automate your maintenance tasks? What tools do you use? How do you ensure that maintenance tasks don't overlap, and that each task has sole use of the PC while it runs? Are there better ways of scheduling tasks that don't normally integrate with the Task Scheduler? Join in the discussion!

Editor's Note: To read more columns by Fred Langa and check out InformationWeek.com's new Windows Tech Center.

To discuss this column with other readers, please visit Fred Langa's forum on the Listening Post.

To find out more about Fred Langa, please visit his page on the Listening Post.

About the Author(s)

Never Miss a Beat: Get a snapshot of the issues affecting the IT industry straight to your inbox.

You May Also Like


More Insights