Is it possible to use windows scheduler and the default built in defrag utility to defragment a Windows 2000 Server on a regular basis without having to visit the remote site where it is housed?
Yep. Heres the .vbs code to auto run defrag in win2k.
set WshShell = CreateObject("WScript.Shell"
'Launch Defrag from the command line and wait for a second
WshShell.Run "dfrg.msc"
WScript.Sleep 1000
'Wait until the application has loaded - Check every second
While WshShell.AppActivate("Disk Defragmenter" = FALSE
wscript.sleep 1000
Wend
'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
'Send a D to start the defrag
WshShell.SendKeys "D"
wscript.sleep 1000
if WshShell.AppActivate("Defragmentation Complete" = TRUE then
' no way it's already defragged! must be a utility partition!
'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send a DOWN key to arrow down to C: (hopefully)
WshShell.SendKeys "{DOWN}"
WScript.Sleep 200
'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
'Send a D to start the defrag
WshShell.SendKeys "D"
wscript.sleep 1000
end if
'Wait until the defrag is completed - Check for window every 5 seconds
While WshShell.AppActivate("Defragmentation Complete" = FALSE
wscript.sleep 5000
Wend
'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
I tried using the afore mentioned VB script solution and it seemed pretty tempramental and unreliable. I also couldn't establish if it would run when not logged in as administrator (it not being a great idea to leave the admin account logged on).
I found a little .exe called AutoDefrag (1.2) which works pretty well but I think you still need to be logged on to run it.
As for the original question. There is no built in way of scheduling defrag, strange but true.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.