Automating the Disk Defrag Process on a XP Machine

Gman496

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.


frag1.jpg



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


frag2.jpg



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


frag3.jpg



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:


frag4.jpg



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


frag5.jpg



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.


frag6.jpg



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:


frag7.jpg



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


frag8.jpg



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.



-
 
I use IOBit Smart Defrag, but I appreciate knowing the process for doing other things with it. Thanks mate :)
 
Back
Top