strComputer = "."
Dim Wmi : Set Wmi = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim ObjItem,ColItems,GB, Var1
GB = Int(1073741824)
Set ColItems = Wmi.ExecQuery("SELECT * FROM Win32_LogicalDisk",,48)
For Each ObjItem in ColItems
If ObjItem.DriveType = 3 Then
If InStr(ObjItem.Caption,"C") Or InStr(ObjItem.Caption,"c") Then
Var1 = objItem.Size - objItem.FreeSpace
Act.Popup "Preparing To Defrag This Drive" & vbCrLf &_
Space(3) & "Drive Letter"& vbTab & ObjItem.Caption & vbCrLf &_
Space(3) & "Volume Name" & vbTab & objItem.VolumeName & vbCrLf &_
Space(3) & "Total Size" & vbTab & FormatNumber(objItem.Size/GB,2) & " GB" & vbCrLf &_
Space(3) & "Free Space" & vbTab & FormatNumber(objItem.FreeSpace/GB,2) & " GB" & vbCrLf &_
Space(3) & "Used Space" & vbTab & FormatNumber(Var1/GB,2) & " GB", 3,"Defrag",4128
Act.Run("Defrag.exe " & ObjItem.Caption &"\"),2,True
End If
End If
Next
Act.Popup "Finished The Defrag",7,"Finshed Defrag",4128