Defragment Multiple Drives

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Defragment Multiple Drives

Post by Rain » Thu Jun 05, 2008 10:59 am

Defragment Multiple Drives

Submitted by: Rain

Code: Select all

//Set If d.DriveType = to " 1 Then" to
//defrag all Removable drives

//Set If d.DriveType = to " 2 Then" to
//defrag all Fixed drives

//Set If d.DriveType = to " 2 OR 1 Then" to
//defrag all Fixed and Removable drives

VBSTART
Set WshShell = CreateObject("WScript.Shell")

Dim fso, d, dc
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

Set WshShell = Nothing
VBEND

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts