Here I have a simple Process creator and I want to use WMI to defrag the hard drive selected and show a progress bar while it works, here is what I have
DefragForm.vb
Was wondering if anyone can shine some light on this.
There errors show on MyProcess.Start() "Failed to find directory"
DefragForm.vb
Code
Imports System.Management
Public Class Defrag
Dim myProcess As New Process
Dim myProcessStartInfo As New ProcessStartInfo("c:\Windows\System32\Defrag.exe", "C: /A /U")
Public Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim drives As System.IO.DriveInfo() = System.IO.DriveInfo.GetDrives
For i As Integer = 0 To drives.Length - 1
ComboBox1.Items.Add(drives(i).ToString)
Next
ComboBox1.SelectedIndex = 0
End Sub
Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim myStreamReader As System.IO.StreamReader = myProcess.StandardOutput
Dim myString As String = myStreamReader.ReadLine()
If myString = Nothing Then
Else
Label1.Text = myString
End If
End Sub
Sub AetherButton1_Click(sender As Object, e As EventArgs) Handles AetherButton1.Click
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo = myProcessStartInfo
myProcess.Start()
Timer1.Start()
End Sub
End ClassThere errors show on MyProcess.Start() "Failed to find directory"

