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!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Juha Saarinen

PC World
Show Comments


James Cook University - Master of Data Science Online Course

Learn more >


Sansai 6-Outlet Power Board + 4-Port USB Charging Station

Learn more >



Back To Business Guide

Click for more ›

Brand Post

Most Popular Reviews

Latest Articles


PCW Evaluation Team

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.

Walid Mikhael

Brother QL-820NWB Professional Label Printer

It’s easy to set up, it’s compact and quiet when printing and to top if off, the print quality is excellent. This is hands down the best printer I’ve used for printing labels.

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?