Automating the Disk Defrag Process on a XP Machine


Super Moderator
Staff member
Starting in Control Panel (Performance and Maintenance, XP Pro non classic view), double click on Scheduled Tasks. Then double click on Add a Scheduled Task.


Click Next. You'll be presented with a list of programs to choose from:


Unfortunately the tool we want, defrag.exe, isn't on that list so, Click on Browse...:


Browse and you'll find defrag.exe at C:\Windows\System32\defrag.exe. Click Open. Next, you'll need to give the task a name and begin choosing the schedule:


You can choose a different name for the task if you like. Click on Weekly and then click Next:


As I indicated, I've selected 3AM every Sunday. Click Next. Each scheduled task is run as if it were a separate login to your machine, so at this point you'll need to enter a login account and password that the system should use to run the task. Click Next.


And you're done! Click Finish, and the task will now run automatically every Sunday at 3AM.

* Now, there's a problem with what we've done so far: there's no log of the results. Defrag might run, but any messages it might output are lost. Unfortunately there's no built-in solution, but that doesn't stop us.

The approach I take is fairly simple. First, use notepad to create a command file containing this single line:

defrag >c:\defrag.log 2>&1

Save that as c:\windows\loggeddefrag.cmd

That command file runs defrag.exe and saves all normal and error output to the file "c:\defrag.log". Try it. You can run "loggeddefrag" in a Windows Command Prompt, and when it completes you can have a look at the log it creates.

Now we just need to update our scheduled task.

Once again in Control Panel (Performance and Maintenance, XP Pro non classic view), double click on Scheduled Tasks. This time right-click on the task we created: "defrag", and click on Properties:


Now simply change the C:\WINDOWS\SYSTEM32\defrag.exe to the command file we just created: c:\windows\loggeddefrag.cmd


Press OK, and you'll have to re-enter the password for the account that will be used to run the scheduled task.
Now you're really done. Check that log file each Sunday morning and you'll see that the defragmenter has run as well as any errors it might have encountered along the way.



Super Moderator
Staff member
Thread starter
Thanks Gman. :)

I personally use TuneUp Defrag.

I use Auslogics Disk Defrag myself & can't fault it.

You can use the above scheduling procedure to run anything really, I was just using Defrag as an example :)



Super Duper Modulator
Staff member
I use IOBit Smart Defrag, but I appreciate knowing the process for doing other things with it. Thanks mate :)