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!


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


PCW Evaluation Team

Luke Hill


I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Laura Johnston

MSI GS65 Stealth Thin

If you can afford the price tag, it is well worth the money. It out performs any other laptop I have tried for gaming, and the transportable design and incredible display also make it ideal for work.

Andrew Teoh

Brother MFC-L9570CDW Multifunction Printer

Touch screen visibility and operation was great and easy to navigate. Each menu and sub-menu was in an understandable order and category

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?