Jump to content
Sign in to follow this  

Defrag your Windows 2000 partitions

Recommended Posts

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


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

<-- end copy -->

Share this post

Link to post
Share on other sites
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...