dmhd.vbs

11:10:00 AM |

'**************************************************************************
'
' *** 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
'
'**************************************************************************
'
'
' SPEED UP SLOW COMPUTER WITH THIS SIMPLE UTILITY TO DEFRAG HARD DRIVES
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'
' WHAT THIS SCRIPT DOES:
' =====================
'
' 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
'
'
' CHANGE LOG
' ----------------------------------------------------------
' 9/22/2011 works with Vista and 7. Turns on and checks for Windows updates
' 10/23/2008 Added description and updated PAD file
' 2/1/2005 added this time stamp & other cosmetic changes
' ==========================================================
'
'
' BEGINNING OF SCRIPT
' ===================
'
' Initialize
' ----------

If WScript.Arguments.length =0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument with leading blank space, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else

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

' turn on and check for updates
' -----------------------------

Return = WshShell.Run("wuauclt.exe /resetauthorization /detectnow", 1, TRUE)

' close down
' ----------
End If

Set WshShell = Nothing

' DISCLAIMER
' ==========
' The information contained in this file is for general information purposes only. The information is provided by "DeBog.com" and whilst we endeavour to keep the information up-to-date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the file or the information, products, services, or related graphics contained on the file for any purpose. Any reliance you place on such information is therefore strictly at your own risk.
'
' In no event will we be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this file.
'
' Through this file you are able to link to other websites which are not under the control of "DeBog.com". We have no control over the nature, content and availability of those sites. The inclusion of any links does not necessarily imply a recommendation or endorse the views expressed within them.
'
' Every effort is made to keep the file up and running smoothly. However, "DeBog.com" takes no responsibility for, and will not be liable for, the file being temporarily unavailable due to technical issues beyond our control.