Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduled Defrag

Status
Not open for further replies.

bowserj

MIS
Dec 12, 2000
29
US
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?

Thanks
 
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}"
 
Or you can buy Executive Software Disk Defragmenter and let handle everything for you. GlennA
MIS






 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top