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?
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
Wend
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
Wend
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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.