How to Automate Disk Defragging in Windows XP

Here's how to set XP to automatically defrag the system hard drive.

Jeremy Lesniak, Contributor

June 22, 2011

2 Min Read

A large number of companies are still running XP. To keep your client machines running smoothly, it's always good to defrag the hard drive on a regular schedule. You can do it manually, but would need to rely on the end user to do so. Here's how to set XP to automatically defrag on a schedule.

To do this, you'll need an administrator level account with a password. All user-level scheduled tasks need a password in XP.

First, create a batch file. From the start menu, select run and in the text field type: cmd. Hit Enter.

In the command line, navigate to a folder where you’d like to save the batch file using the cd (change directory) command.

I changed to the utilities directory on my C drive by typing: cd utilities. After you select a subdirectory, type the following at the C:\prompt: echo defrag c: -f > defragc.bat

You just created the file. There’s no confirmation or other message if you did it correctly. Close out the command window.

Now from the Start menu, head to Programs >> Accessories >> System Tools >> Scheduled Tasks

Click Add Scheduled Task.

Now in the Scheduled Task Wizard, click Browse.

In the Browse menu, click Navigate to the location of the saved batch file. Select it and click Open.

Select how often you want the system to defrag. Click Next.

Enter a scheduled day of the week and a time for the defrag task. I usually schedule it for sometime after normal business hours. Remember your computer must be powered on for the job to run. Click Next.

Enter the password for the account the job will run under. By default, it will ask the password for the account you’re logged in as. Click Next.

Click Finish and you’re done. Setting up a regular disk defrag is an excellent habit to get into -- especially in XP, and now you don’t have to think about it. This will provide better performance of workstations, and less work for IT.

Based in Duxbury, VT, Jeremy Lesniak is a senior contributor at BYTE. Follow him @jlesniak and email him at [email protected].

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