Sarasota PC Monitor
Practicing the Black Art (03/04)
Automate Defrag in Windows XP
by Vinny La Bash, vlabash@home.com
Member of the Sarasota Personal Computer Users Group, Inc.A key element of good PC performance is a well-organized hard drive. Fragmentation occurs when a file is split into separate pieces and scattered all around a disk. The rate of fragmentation increases as data files are constantly written and updated. Fragmentation is the enemy of hard disk performance.
Fragmentation can cause severe performance degradation on a PC because disk drive heads must perform multiple seek operations when accessing a file. Defragging reduces the need for the drive heads to race all around the disk surface to pick up scattered pieces of different files. To bring your disk drive to an optimum performance level, you need to execute a process called defragmentation, or defrag as it is commonly known. This is a method of reorganizing the contents of a disk so that all of a file's contents are written in a single contiguous block. This generally requires a special utility called "Disk Defragmenter", provided by Microsoft as part of the XP operating system. There are many third party defragmentation available, but we will work with the Microsoft provided tool because it is part of Windows XP, and you don't have to pay extra for it.
A disk drive must have at least 15% free space for defrag to completely do its job. Defrag uses this space as a sorting area for any file fragments it finds on a disk drive. If a drive has less than 15% free space, defrag can only partially defrag it. To increase the free space on a volume, delete unneeded files or move them to another disk. To check the amount of free space you have on any of your drives, open the My Computer icon on your desktop, and from the View menu on the standard toolbar, select the Details view.
After ascertaining that you have enough space for the defrag tool to work properly, you can now go about automating this task. Most manuals on Windows XP will tell you that you can't run the defrag tool on a scheduled basis. That's true unless you know some good old DOS tricks from the days of command lines and batch files. Let's combine the old with the new and do what "they" say can't be done.
- We need to open the Task Scheduler, so click on the Start button and navigate to All Programs - Accessories - System Tools - Scheduled Tasks.
- The Scheduled Tasks dialog box appears. Left Click on Add Scheduled Task.
Click the Next button on the Scheduled Task Wizard dialog box.

- in alphabetical order. Unfortunately, the Disk Defragmenter utility we need is not one of the items on the list. Click the Browse button.
- On the next screen navigate to the C:\Windows\System32\defrag.exe file. Your screen should resemble the illustration showing the Select Program to Schedule dialog box.
- The next screen prompts you to type a name for your task. You could leave it alone or change it to something more meaningful. After naming the task, choose how often to run the program. Daily is probably overkill. Either Weekly or Monthly are probably the two best choices for most people. We will go with Weekly.
- Adjust the time of day you want the defrag program to run.
- Decide if you want to run the program every week, every two weeks, etc.
- Select the day or days of the week to run defrag.
- Click the Next button. On the following screen, enter and confirm your Windows logon password. If you don't enter your password, the defrag program may not run at the scheduled time.
- Check the box where it says Open advanced properties for this task when I click Finish.
- This is what we have been working toward. In the Run: box add c: and -f so that the line looks like C:\WINDOWS\system32\defrag.exe c: -f
- The C: character tells the program that you want to defrag the C: disk. If you had a partition designated as the D: drive, you would type D: or E: or whatever the letter assigned to the disk or partition.
- The -f character forces the program to defrag the disk.
- When you are sure the line is typed correctly, click on the Schedule tab to ensure your choices are correct.
- Click OK.
- If a dialog box appears requesting your password again, enter it and then confirm it.
- Click OK and you're done.
Your system is now set to defrag your hard drive or partition on a regular schedule. To automate defrag for each partition, create a scheduled event for each drive.
While automating the defrag process is certainly possible and easy to do, it does have its trade-offs. There is no graphical interface, and you won't get any disk drive analysis or reports of any kind. It won't run if your machine is in standby or hibernate. Yet, automating defrag can be a more convenient way of coaxing better performance out of your system. You can defrag disks formatted as FAT, FAT32, and NTFS. Try it! You might like it! :
Return to Vinny La Bash's Index
Copyright 2004. This article is from the March 2004 issue of the Sarasota PC Monitor, the official monthly publication of the Sarasota Personal Computer Users Group, Inc., P.O. Box 15889, Sarasota, FL 34277-1889. Permission to reprint is granted only to other non-profit computer user groups, provided proper credit is given to the author and our publication. We would appreciate receiving a copy of the publication the reprint appears in, please send to above address, Attn: Editor. For further information about our group, email: admin@spcug.org/ Web: http://www.spcug.org/
The Sarasota Personal Computer Users Group, Inc. has 1,100+ members and was established in 1982. We are members of the Assoc. of PC User Groups (APCUG), the Florida Assoc. of PC Users Groups, Inc., and we are members of the America Online Ambassador Program.
See http://www.spcug.org for all reviews from the Sarasota PC Monitor, go to the Newsletter Section.