Windows XP scheduled tasks and defragmenting?

7

1

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?

Gathris

Posted 2009-09-04T06:57:22.257

Reputation: 187

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 – 2009-09-04T07:48:51.157

:)). You have a very active imagination, Gnoupi. – alex – 2009-09-04T08:03:44.887

@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 – 2009-09-04T15:38:23.257

Answers

9

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.

Breakthrough

Posted 2009-09-04T06:57:22.257

Reputation: 32 927

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 – 2009-09-04T15:41:32.020

3

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.

John T

Posted 2009-09-04T06:57:22.257

Reputation: 149 037

1

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

Col

Posted 2009-09-04T06:57:22.257

Reputation: 6 995

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 – 2009-09-04T22:41:02.297

0

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

Registered

Posted 2009-09-04T06:57:22.257

Reputation: 261

I agree with scheduling. However, I'd also recommend

http://www.splinterware.com/download/index.htm

You might need a bit of Autohotkey magic to make the defrag happen.

– outsideblasts – 2009-09-04T08:30:30.557