A question about Vista's built-in Disk Defragmenter

Discussion in 'Windows Desktop Systems' started by madmatt, May 8, 2007.

  1. madmatt

    madmatt Bow Down to the King Political User

    Messages:
    13,312
    Location:
    New York
    Has anyone figured out how to defragment just one disk? Clicking "Defragment now" appears to perform the action on all disks.
     
  2. andy_rose

    andy_rose Moderator

    Messages:
    1,237
    Here's a script to just defrag only drive c in vista.
    Save it as whatever.vbs

    Code:
    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
    
     
    Last edited by a moderator: May 8, 2007
    ray_gillespie and madmatt like this.
  3. ray_gillespie

    ray_gillespie Moderator Staff Member Political User

    Messages:
    1,692
    Location:
    Birmingham, UK
    Nice one Andy, I'll take a copy of that if you don't mind :)
     
  4. Sazar

    Sazar F@H - Is it in you? Staff Member Political User Folding Team

    Messages:
    14,905
    Location:
    Between Austin and Tampa
    I've never been able to use the dang thing.

    Keeps saying my disks don't need to be defragged :(

    Bleh.
     
  5. andy_rose

    andy_rose Moderator

    Messages:
    1,237
    You know you can just click "defragment now" anyway right?
     
  6. madmatt

    madmatt Bow Down to the King Political User

    Messages:
    13,312
    Location:
    New York
    I'm not too fond of the built-in utility. I like that you can schedule it but I don't like that you can't choose which drive(s).
     
  7. epk

    epk Moderator Political User Folding Team

    Messages:
    1,241
    Location:
    Buenos Aires
    yeah... me too

    i hope they upgrade it in sp1 (although its unlikely)
     
  8. andy_rose

    andy_rose Moderator

    Messages:
    1,237
  9. madmatt

    madmatt Bow Down to the King Political User

    Messages:
    13,312
    Location:
    New York
    The only reason I don't like it is the fact that you cannot choose which drive. I could care less about the drive map.

    Thanks for the script, I will defiantly check it out.
     
  10. Sazar

    Sazar F@H - Is it in you? Staff Member Political User Folding Team

    Messages:
    14,905
    Location:
    Between Austin and Tampa
    I don't want to disobey the almighty kernel :eek:
     
  11. epk

    epk Moderator Political User Folding Team

    Messages:
    1,241
    Location:
    Buenos Aires
    cool article andy... apparently i was wrong and longhorn updates (of the defrag util) will be available for vista

    cool!