The defrag in 200/xp is actually a cut-down version of a product called Diskeeper, made by Executive Software. You cannot schedule defrags, or do concurrent drive defrags, but if you purchase the real thing, (download a trial first - it is an excellent piece of software - pagefile defragging, mft, the works) you can use scheduling and concurrent drive defrags.
It also has 'Smart Scheduling' which will asses your drive and see if it needs it or not. If it doesn't it will have another look at it's leisure. It really is spot on.
There is a script out there that allows you to use the existing defragmention program in Windows and schedule it in 2000. Do know whether this is what you want or not?
' This script launches defrag and sends keys to the UI in order to automate the defrag
' process.
'
' Based on code from Windows & .Net Magazine
' Graham Reeds, 2002
' start the script and get access to the shell
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 500
' get the number of mounted drives
set FSysObject = CreateObject("Scripting.FileSystemObject"
set AllDrives = FSysObject.Drives'
FirstTime = TRUE
On Error Resume Next
For Each iDrive In AllDrives
If iDrive.DriveType <> 1 And iDrive.DriveType <> 3 And iDrive.DriveType <> 4 Then
If FirstTime = TRUE Then
' Send a tab key to highlight the current Drive
WshShell.Sendkeys "{TAB}"
WScript.Sleep 500
End If 'FirstTime = TRUE
' if this isn't the first time pick the next drive letter
If FirstTime = FALSE Then
' Send a down key key to highlight the next Drive
WshShell.Sendkeys "{DOWN}"
WScript.Sleep 500
End If 'FirstTime = FALSE
FirstTime = FALSE
' Send an ALT-A key to bring down the defrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
' Send a D to start the defrag for the drive:
WshShell.SendKeys "D"
' 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
End If ' iDrive.DriveType
Next 'iDrive
' 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}"
Just set this to run at a particular time in task scheduler. May need to be adapted to run defrag on multiple drives.
does anyone know whether a product like Srvany can run a VBS script like this as a service for running when not logged on
although as you say the GUI is needed for the sendkeys move so you probably need to be logged on
Also as i found over the weekend, this script works really well!
until as i found if it comes across a drive with insufficent space (i modified the script to defrag 8 drives but the last one only has 300Mb left) it was asked a different question and stopped!
Thanks to Tonykblen for the great script. It works like a charm on 2 Win2K Pro workstations, but on my 3rd Win2K Pro machine, it hangs. I added some code to write to a log to see where it's hanging and its on this code (below). It just loops, meaning it hasn't detected that the app. is active. I scheduled it for 3:00 a.m., with a Task Scheduler shutdown after 5 hours if still running, and the scheduler had to force a shutdown since it was still looping on the AppActivate test. The defrag mmc seems to have launched (I can see it in the Task Manager), but the GUI is not visible on the screen.
' Wait until the application has loaded - check every second
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
Wend
Any ideas as to why it can't "activate" the defrag. app.?
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.