A question about Vista's built-in Disk Defragmenter

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
Has anyone figured out how to defragment just one disk? Clicking "Defragment now" appears to perform the action on all disks.
 

andy_rose

OSNN Veteran Addict
Joined
15 May 2004
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:

ray_gillespie

OSNN Veteran Addict
Political Access
Joined
21 Mar 2002
Messages
1,693
Nice one Andy, I'll take a copy of that if you don't mind :)
 

Sazar

F@H - Is it in you?
Political Access
Joined
12 Apr 2002
Messages
14,905
Has anyone figured out how to defragment just one disk? Clicking "Defragment now" appears to perform the action on all disks.

I've never been able to use the dang thing.

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

Bleh.
 

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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).
 

epk

OSNN Veteran Addict
Political Access
Joined
22 Oct 2006
Messages
1,240
yeah... me too

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

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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.
 

epk

OSNN Veteran Addict
Political Access
Joined
22 Oct 2006
Messages
1,240
cool article andy... apparently i was wrong and longhorn updates (of the defrag util) will be available for vista

cool!
 

Members online

No members online now.

Latest forum posts

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,414
Members
5,591
Latest member
nodee