'************************************************************************** ' ' *** If you are reading this, *** ' [and you expected to defrag your drives] ' Please save this page as dmhd.vbs and double click it to use ' '************************************************************************** ' ' This script calls cleanmgr /sageset:99 if it hasnt been run before, ' to setup which files will be removed in the cleaning process. ' It then calls cleanmgr /sagerun:99 to clean those files from all drives ' finally, it calls defrag -f forcing defragmentation of all drives ' ' A current copy of this file is kept at: ' http://www.DeBog.com ' http://www.DefragMyHardDrive.com ' ' CHANGE LOG ' ---------------------------------------------------------- ' 2/1/2005 added this time stamp & other cosmetic changes ' ========================================================================= ' Initialize ' ---------- Dim read, fso, d, dc Set WshShell = WScript.CreateObject("WScript.Shell") ' Check for sageset:99 registry key and setup if not exist ' -------------------------------------------------------- On Error Resume Next read = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files\StateFlags0099") 'Then Err.Clear if read then 'do nothing else Return = WshShell.Run("cleanmgr /sageset:99", 1, TRUE) end if ' clean up all hard drives ' ------------------------ Return = WshShell.Run("cleanmgr /sagerun:99", 1, TRUE) ' force defrag on all hard drives [by Doug Knox] ' ---------------------------------------------- Set fso = CreateObject("Scripting.FileSystemObject") Set dc = fso.Drives For Each d in dc If d.DriveType = 2 Then Return = WshShell.Run("defrag " & d & " -f", 1, TRUE) End If Next ' close down ' ---------- Set WshShell = Nothing