Windows XP scheduled tasks and defragmenting?

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.

Solution

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).

Why

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.


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

@ECHO OFF
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.