Partager via


Random XP tip: Scheduled disk defragmentation

It came to my attention that a lot of folks don't know about one of the very nice additions that came long with the rest of Windows XP: A command-line interface to the disk defragmenter. This means it's now easy to setup a scheduled task to defrag your hard disk(s), whereas with Windows 2000 it was rather difficult.

If you're already familiar with scheduled tasks, all you need to know is that the tool is located at %WinDir% \system32\defrag.exe, and takes the drive letter as an argument (e.g. "c:\winnt\defrag.exe c: ".

If you've never created/managed a scheduled task before, don't worry - it's not very hard:

  1. Bring up Control Panel
  2. Double-click on "Scheduled Tasks"
  3. Double-click on "Add Scheduled Task"
  4. Click "Next", then click "Browse"
  5. Type (or paste in) %windir%\system32\defrag.exe (then click Open)
  6. Change the name of the task from "defrag" to "Defrag C" (note that you can't put a colon in the name of the task)
  7. Select "Weekly" for the task interval (if you're really obsessed with performance, you can set it to daily), press "Next"
  8. Change the start time - I usually use 04:00am. Select a day of the week. The only caveat here is to be sure to pick a time the machine is actually on (so if you turn your computer off every night, 4am is probably not the best choice); press Next
  9. Enter an administrator user and password, press Next
  10. Check the box for advanced properties, then click Finish.
  11. When the advanced properties come up, add the drive letter to the end of the run box, you should see something like this afterwards (note the colon): C:\WINNT\system32\defrag.exe c:
  12. You shouldn't need to change any of the other settings, but feel free to look them over

I assure you the fact that this was a 12-step process is entirely coincidental. If you have multiple hard drives, repeat steps 3-12 for each - be sure each task has a unique name.

When you're done, you should see something like this:

That's all there is to it! You may want to bring up scheduled tasks every so often and make sure they're working as expected (last result is 0x0). If you see 0x7, that means the disk has less than 15% free space and therefore defrag.exe won't run by default - you can add -f to the command if you want it to defrag anyway, but I generally advise freeing up some space instead. If you see 0x1, the password is probably wrong or out of date.

Comments

  • Anonymous
    April 14, 2006
    You can also add the /sageset & /sagerun command to set the defaults for the program.

    http://spaces.msn.com/bhandler/Blog/cns!1pt1v0Q4vD8jSvNS4lqdAuug!373.entry


  • Anonymous
    April 14, 2006
    Interesting (and apparently undocumented). I'll have to give that a try!
  • Anonymous
    May 19, 2006
    The comment has been removed
  • Anonymous
    June 01, 2006
    For all kinds of automated tasks I strongly recommend VisualCron.

    // Evan
  • Anonymous
    June 02, 2006
    I looked at the site - I'll definitely have to take this for a spin. Thanks!