0

There is no error in the program but control is not going inside the for loop because objVolume is nothing. The Datatype of Follwing Objects are right or wrong...Is
Dim objWMIService, objVolume, colVolumes, errResult As Object.
Is the foll. code defrags the computer....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objWMIService, objVolume, colVolumes, errResult As Object
        objWMIService = GetObject("winmgmts:\\" & Environment.MachineName & "\root\cimv2")
        colVolumes = objWMIService.ExecQuery _
            ("Select * from Win32_Volume Where Name = 'C:\\'")
        For Each objVolume In colVolumes
            errResult = objVolume.Defrag()
            If errResult = 0 Then
                MsgBox("Drive " & objVolume.Name & " successfully defragged.")
            Else
                MsgBox("Drive " & objVolume.Name & " could not be defragged.")
                Err.Clear()
            End If
        Next
    End Sub
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Teme64
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.