Ask the Expert

A script for Windows 2000 defragmentation

How do you schedule defragmentation using the Windows 2000 defrag tool, Dfrg.msc? It doesn't defrag automatically. Is there a free tool out there that I can use to schedule the defragment?

Requires Free Membership to View

You can actually create a Windows Scripting Host script to do so. As luck would have it, I recently published a tip that involves using a script that scan be scheduled for defragging. Here it is:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "dfrg.msc"
WScript.Sleep 1000
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
WshShell.SendKeys "%A"
WScript.Sleep 200
WshShell.SendKeys "D"
While WshShell.AppActivate("Defragmentation Complete") = FALSE
wscript.sleep 5000
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
WshShell.Sendkeys "%{F4}"

This was first published in July 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: