Emnico in Swindon and its partners
in the UK and Europe provide:

» IT Support Services and Products
» Bespoke Software Development


Contact our Swindon office on:
+44 (0)1793 614 700
to discuss your IT needs.


CLOSE IT
Emnico Logo
Your Virtual Technology Team
Delivering Peak Performance
Category: Type: Order:
Search For:  
Home > Library > Defragment Disk

Defragment Disk

This script will defragment all hard drives on Windows Vista and Windows Server 2003.
Added 338 days ago by Emnico
Download
Review
Back
223Views
This script has been successfully tested by Emnico and is verified to be working.

Source code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")

For Each objVolume in colVolumes
	errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
    If errResult = 0 Then
        Wscript.Echo "Volume name: " & objVolume.Name
        If blnRecommended Then
           Wscript.Echo "You should defragment this volume."
           
           
    		Wscript.Echo "Please wait while drive " & objVolume.Name & " is defragged."
    		Wscript.Echo
    		errResult = objVolume.Defrag()

    		If errResult = 0 Then
        		Wscript.Echo "Drive " & objVolume.Name & " successfully defragged."
    		Else
        		Wscript.Echo "Drive " & objVolume.Name & " could not be defragged."
        		Wscript.Echo "Error number " & errResult & " occurred."
        		Err.Clear
    		End If
   
        Else
           Wscript.Echo "You do not need to defragment this volume."
        End If
	End If
Next


User Reviews

Recommended by Emnico 
by Emnico on 21 October 2009
Defragmenting the hard disk of a computer is an simple and effective way to improve system performance. This script removes the hassle of manually defragmenting your hard disks and is most useful when scheduled to run at regular intervals.


| Privacy policy | Environmental policy | Site map |