Dim p As New Process
Dim si As New ProcessStartInfo
si.FileName = "cmd"
si.CreateNoWindow = True
si.RedirectStandardInput = True
si.RedirectStandardOutput = True
si.UseShellExecute = False
p.StartInfo = si
p.Start()
Dim sr As StreamReader = p.StandardOutput
Dim sw As StreamWriter = p.StandardInput
sw.WriteLine("defrag.exe c: -a")
sw.WriteLine("exit")
Dim ofile As New StreamWriter("c:\t.txt")
ofile.Write(sr.ReadToEnd)
ofile.Close()
sw.Close()
sr.Close()