Linux-Noob Forums

Full Version: Defrag your Windows 2000 partitions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

The official word from MS on scheduling a defrag is "Nope." They say you must purchase 3rd party utilities to be able to schedule defragging.

 

However, I had the same problem in the past and came across a VBScript that would take care of the problem. It basically just runs the defrag MMC and uses send keys command to automate the process. It then sits in a loop until it sees that the defrag is complete and shuts it down. The code is below, just copy and paste it to notepad then save the file as defrag.vbs and then use task scheduler to schedule it.

 

<-- start copy below this line -->

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}"

<-- end copy -->