Hi,
You may run the defragment using the Command prompt and you may run commands inside the visual basic, the following is an example:
Imports System.Diagnostics
Module Module1
Sub Main()
Try
' Create a new process to run the defrag command
Dim defragProcess As New Process()
defragProcess.StartInfo.FileName = "cmd.exe"
defragProcess.StartInfo.Arguments = "/c defrag C: /U /V"
defragProcess.StartInfo.UseShellExecute = False
defragProcess.StartInfo.RedirectStandardOutput = True
defragProcess.StartInfo.CreateNoWindow = True
' Start the process
defragProcess.Start()
' Capture and display the output
Dim output As String = defragProcess.StandardOutput.ReadToEnd()
defragProcess.WaitForExit()
Console.WriteLine("Defragmentation Output:")
Console.WriteLine(output)
Catch ex As Exception
Console.WriteLine("An error occurred: " & ex.Message)
End Try
End Sub
End Module