Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
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

4 Answers 4

up vote 9 down vote accepted

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.

share|improve this answer
    
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:

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

share|improve this answer

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%5F4-10759533.html

share|improve this answer
    
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. –  RoyalKnight 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

share|improve this answer
    
I agree with scheduling. However, I'd also recommend splinterware.com/download/index.htm You might need a bit of Autohotkey magic to make the defrag happen. –  outsideblasts Sep 4 '09 at 8:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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