I am trying to set a seduled task to defrag my HDD on a regular basis and following the guide on http://www.microsoft.com/windowsxp/using/setup/learnmore/tips/gehrke1.mspx. It does not work. That process only brings a DOS window which does nothing (well it displays some text about the Microsoft defragging program).

I tried using the "%SystemRoot%\system32\dfrg.msc C:" as the command path that is in the start menu but that brings up the program to start a defrag job and doesn't start automatically.

What am I missing?

  • Isn't the correct word "defragmenting" ? I can't help but picturing defragging as the opposite of fragging. Like a shooter game where you would shoot people back to life. Weird.
    – Gnoupi
    Sep 4 '09 at 7:48
  • :)). You have a very active imagination, Gnoupi.
    – alex
    Sep 4 '09 at 8:03
  • @Gnoupi Well yes the full word is defragmenting but I often here it shortened to Defrag and so we come to defragging but your comment made me LOL.
    – Gathris
    Sep 4 '09 at 15:38

dfrg.msc vs defrag.exe

dfrg.msc is the GUI frontend to the defrag.exe backend tool. What you're essentially doing is invoking the wrong thing, since only defrag.exe takes command line arguments.


Just use the following for the command path:

defrag C: -f

You shouldn't need to specify any paths, since by default, Windows will search for the tool via the PATH environment variable. The -f switch forces defrag to defragment the specified volume, regardless of how fragmented it actually is (the Windows disk defragmenter sometimes doesn't want to run if the fragmentation level is below a certain threshold).


What you're doing is launching the control panel version, when for a scheduled task, you only want to launch the command-line tool (which is the backend to the GUI).

If you type the following when you go to Start -> Run:

dfrg.msc C:

You will see that it only launches the GUI, which is not what you want. That's why you need to replace dfrg.msc with defrag, and the -f switch forces it to defragment even if the tool thinks that it is "unnecessary".

Final note

There's nothing wrong with using the built-in defragmenter, although I would recommend some third-party utilities, which often have the ability to defragment certain files on bootup, automatically prevent MFT fragments, and intelligently order certain files on the disc (to make it quicker to retrieve those files).

Again, this is just something to keep in mind - there is nothing wrong with the built in defragmenter. There are only limitations with it if you are running Windows 2000 or earlier.

  • I tried the defrag.exe but only brought up the command window so I will have to try your -f command when I get home.
    – Gathris
    Sep 4 '09 at 15:41

You could just use it from within a batch script. Paste this into something like defrag.bat and place it where you wish:

defrag c: > report.txt

that way, you have a report of how the defrag process went as well. If you don't wish to have a report, simply remove the > report.txt portion.


Your best bet is just to download a defrag tool that does scheduling, I'd recommend smartdefrag http://download.cnet.com/Smart-Defrag/3000-2094_4-10759533.html

  • SmartDefrag allows you to schedule defrags as well as optionally optimize file placement. It's real power, though, comes from its ability to autodefragment all of your volumes while your system is idling. This helps to keep your HDDs in a consistently defragmented state. It's also free and has a CNET Editor's Choice recommendation. Sep 4 '09 at 22:41

Try this: Microsoft Task Scheduler

The Microsoft Task Scheduler is an amazing little FREE tool that (in most cases) comes already with your Windows installation and "hides" in the "Control Panel" folder which is located in the "My Computer" folder on your desktop. In the following text we share our experiences to help you to make most out of this tool.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.