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

Dig deeper on Windows Operating System Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close