Schedule Weekly Defrags for Windows XP

As a part-time freelance systems administrator I have often been approached with questions regarding computer performance (or lack thereof.) Besides upgrading RAM, processor, or other hardware peripherals, one of the first things I suggest is to do a hard drive defrag. I lack the time now to fully explain the ins-and-outs of the defrag process, nevertheless, I wish to show how to setup a computer to run a weekly (or more frequent) scheduled disk defrag.

One of the most useful yet underutilized tools the Windows OS includes is the task scheduler. Now, I do not claim it to be flawless, however in certain circumstances, such as disk defragmentation scheduling, it can come in very handy.

In order to create a new task, we first run the Windows ‘Control Panel’. This can be done either by open the Run dialog from the Start Menu and typing and running the ‘control’ program. For those GUI fanatics, clicking Start | Control Panel will do the same.

Once in the Control Panel, look for the ‘Scheduled Tasks’ applet. This little program launches the tasks application (or tasks folder to those of us who really know what it does.) You’ll notice either a whole slew of previously configured tasks that have been configured by your friendly neighborhood virus scan application or other task intensive applications.

From the tasks windows, click ‘Add Scheduled Task’, this will launch the Scheduled Task Wizard.

The first screen you’ll see is the Welcome screen. Click ‘Next’.

After a sometimes very long delay (the wizard has to rebuild your application list from the registry) you’ll see the application selector window.

As the defrag application usually does not appear as a standard application, we need to browse for it, so click ‘Browse…’.

If you are using Windows XP (home or pro) all you need to do is type in the file name:


The Windows auto-complete will help you out if enabled.

If you are NOT running Windows XP or are unable to locate the defrag with this path, you can manually locate the defrag.exe under your System folder by opening a command prompt and typing:

echo %windir%

and the hit the Enter key.

Once you’ve located the defrag application and have a valid path in the browse applet, click ‘Open’.

You will now be able to name and schedule the task. I usually enter something explanatory like ‘Defrag C Drive’. The title doesn’t really matter, as long as it’s something you’ll remember. Choose your run frequency, I do weekly, then click ‘Next’.

In the time and date applet, set the schedule for the task. My schedule is set to run when I’m am least likely to be on my computer AND a time when another task is not running. Click ‘Next’.

Since this task is going to be automatically run, the OS needs to know with which user account to run it (or runas account.) I usually select the administrator account, or an account that has full permissions to run the defrag application and modify drives. Click ‘Next’.

At the schedule success screen, click ‘Open advanced properties when I click Finish’ box and then click ‘Finish’.

This is the advanced task editor applet. First we need to tell the defrag program which partition we want to defrag. Most computers will be configured with only one partition so this should be pretty straight forward. At the end of the ‘Run’ string, put a space then type the letter of the drive you wish to have defragged. In my case, the C:\ drive. So after you’re done, your command should look something like this:

c:\windows\system32\defrag.exe c:\

Now that we’ve told the defrag program which drive to defrag, click ‘Settings’.

In the Settings dialog we want to set the ‘Stop the task if runs for:’ value (the kill time) to 4 (or more or less depending on the size of your partition and the speed of your system.)

Now that we’ve limited the run time for this task we’re ready to go. Click ‘Ok’ to close out the advanced settings applet.

Congratulations! You’ve successfully scheduled a Windows Task.

The only thing left to do now is test that the scheduled task will actually run.

First we re-open the ‘Control Panel’ | Scheduled Tasks applet. Locate the task we just created, right-click the task icon and then left-click ‘Run’. After a few seconds right-click the task icon again and check to see if the ‘Run’ command is disabled and the ‘End task’ command is enabled. You can also check your running tasks (CTRL + ATL + ESC) to see if the defrag program is running.

After a long period, the right-click menu should re-enable the ‘Run’ command and disable the ‘End task’ command signalling the task has completed.

If you are still having complications in getting the task to run, you can manually troubleshoot the defrag program by opening a command prompt and typing in the same command you entered as the run command for the task:

c:\windows\system32\defrag.exe c:\

You can troubleshoot any errors that are returned here.

Though there are more complex and robust partition defrag software solutions available, for those of us who are perfectly fine with the Windows provided defrag application, scheduling regular partition defrag routines can drastically increase your system performance without requiring the purchase of expensive and sometimes time consuming system upgrades.

Microsoft has a couple of articles on performing this same process.

How to Automate Disk Defragmenter Using Task Scheduler Tool in Windows XP
Schedule a Task to Defragment Drives


Comments are closed.