Q

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 last published in July 2003

Dig Deeper on Windows Operating System Management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close