XP Pro: Scheduling disk defragging

One small but very welcome improvement in Windows XP Professional over Windows 2000 Professional is the ability to run the disk defragmenter through the command line. Yes, finally you can schedule disk defragging to take place at regular intervals, without resorting to crude VBScript hacks like the one I described in a recent Windows 2000 Professional Here's How column (March, page 106) or having to purchase expensive third-party utilities.

The executable you are looking for is called DEFRAG.EXE, naturally enough, and resides in %windir%\system32. As an aside, there are two other defrag-related executables there as well: DFRGNTFS.EXE and DFRGFAT.EXE. They are carry-overs from Windows 2000, but can't be launched from the command line or via Explorer, so they're no good for what we want to do.

As with all Windows command line utilities, add "-?" to get the help for how to use DEFRAG.EXE:

C:\>defrag.exe -?

Windows Disk Defragmenter

Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.Usage:defrag.exe [-a] [-f] [-v] [-?] volume drive letter or mount point (d: or d:\vol\mountpoint) -a Analyze only -f Force defragmentation even if free space is low -v Verbose output -? Display this help textSo, to analyse the defragmentation of drive C:, we would do:C:\>defrag c: -a -v The "-v" switch gives us much more diagnostics output, so I recommend you use it. The "-f" switch allows you to run DEFRAG.EXE on very full disks - for NTFS defragmentation to be effective, about 13 per cent free space is needed to shift data around.To schedule DEFRAG.EXE to run at 3 a.m. every Saturday, use the AT command like this:C:\>at 03:00 /every:saturday defrag.exeAdded a new job with job ID = 1Check that the job will take place on the desired day and time like this:C:\>atStatus ID Day Time Command Line------------------------------------------------------------ 1 Each S 3:00 AM defrag.exeTo cancel the task, note the job ID, and do:C:\>at 1 /delete

A slightly more cumbersome way to schedule regular disk defragmentation is to use the graphical Task Scheduler utility. There is a reward for the increased amount of pointing and clicking, though: Task Scheduler offers fine-grained control over the tasks (see below) such as multiple schedules, which is well beyond anything AT can offer.

Begin by going to Start-Control Panel-Scheduled Tasks, and use the Add Scheduled Tasks wizard. You won't see DEFRAG.EXE in the list of programs on the second screen of the wizard, so click the Browse button, go into your \Windows\System32 directory, and select it from there.

Then, name the task (e.g., "Weekly Defrag") and pick when to perform it - the frequency (weekly), start time (03:00 a.m.) every 1 week on Saturday, to copy the above example. If you don't run as Administrator for security reasons, Task Scheduler will ask you which user to run the program as. For DEFRAG.EXE, run it as Administrator, and supply the right password.

The Advanced Options dialogue gives you even more options relating to scheduling of tasks - for instance, if you've got a portable computer, you might not want to run DEFRAG.EXE when it's on battery power. Click on the Settings tab and go to the Power Management section on that page; tick the boxes for "Don't start the task if the computer is running on batteries" and "Stop the task if battery mode begins".

You can also tell Task Scheduler to wake the computer from sleeping/hibernation to carry out the disk defragmentation; also, as a safety precaution, stop the task from looping by telling Task Scheduler to kill it if it's been running continuously for more than a certain amount of time.

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Juha Saarinen

PC World
Show Comments

Brand Post

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Tom Pope

Dynabook Portégé X30L-G

Ultimately this laptop has achieved everything I would hope for in a laptop for work, while fitting that into a form factor and weight that is remarkable.

Tom Sellers

MSI P65

This smart laptop was enjoyable to use and great to work on – creating content was super simple.

Lolita Wang

MSI GT76

It really doesn’t get more “gaming laptop” than this.

Jack Jeffries

MSI GS75

As the Maserati or BMW of laptops, it would fit perfectly in the hands of a professional needing firepower under the hood, sophistication and class on the surface, and gaming prowess (sports mode if you will) in between.

Taylor Carr

MSI PS63

The MSI PS63 is an amazing laptop and I would definitely consider buying one in the future.

Christopher Low

Brother RJ-4230B

This small mobile printer is exactly what I need for invoicing and other jobs such as sending fellow tradesman details or step-by-step instructions that I can easily print off from my phone or the Web.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?