Jump to content
Xtreme .Net Talk

Recommended Posts

  • Administrators
Posted

Something like

  Dim ComputerName As String = ""
       Dim wmi As New ManagementObjectSearcher("Select * from Win32_Volume Where Name = 'C:\\'")


       Dim volumes As ManagementObjectCollection

       volumes = wmi.Get()

       For Each Volume As ManagementObject In volumes
           Volume.InvokeMethod("Defrag", Nothing)
       Next

should do the trick, you will need to add a reference to System.Management.dll as well for it to compile.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Ok.

 

Umm, when I tried this, it came up with the exception: Invalid Class ?

 

 Dim wmi As New ManagementObjectSearcher("Select * from Win32_Volume Where Name = 'C:\\'")
       Dim volumes As ManagementObjectCollection
       volumes = wmi.Get()
       For Each Volume As ManagementObject In volumes
           Volume.InvokeMethod("Defrag", Nothing)
       Next

Posted

Thanks,

but i am making a program that cleans out your pc and defrags it, deletes temp files etc.

 

I could just run Execute defrag.exe but i want a progress bar etc. i wonder if there is any other way since you can't do it in XP.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...