Creating GUI for Diskpart
vb.net Code:
Dim p As New Process
Dim pi As New ProcessStartInfo
pi.UseShellExecute = False
pi.RedirectStandardOutput = True
pi.WorkingDirectory = "C:\windows\system32"
'this for nt* computers
pi.FileName = "diskpart.exe"
p.StartInfo = pi
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("list disk")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
RichTextBox1.Text = (sb.ToString)
This is what I have so far as code. I am trying to create a GUI for the Disk Partition Console. Reason being that if you go to format a hard drive, you may have to use the console if you have to perform an override. I was working on a computer last week where I had to wipe the entire hard drive and it wouldn't let me do so with disk management. So I am trying to create a simple GUI for the diskpart.exe console. I have seen people make simulated console applications. However, with diskpart.exe, its been difficult. There are not a lot of related topics on google or on any forums sites that can help me. I have tried basing it off the way its done with CMD, but have been struggling. I am trying to just get the two programs to communicate I/O and display all the output in a richtextbox. Any tips? this is the code I have managed to come up with. I have had many other codes that all have failed such as:
vb.net Code:
Dim prcDOS As New Process
Dim siDOS As New ProcessStartInfo
siDOS.FileName = "cmd"
siDOS.UseShellExecute = False
siDOS.CreateNoWindow = True
siDOS.RedirectStandardInput = True
siDOS.RedirectStandardOutput = True
prcDOS.StartInfo = siDOS
prcDOS.Start()
Dim srInput As StreamWriter = prcDOS.StandardInput
Dim srOutput As StreamReader = prcDOS.StandardOutput
srInput.WriteLine("diskpart.exe")
srInput.WriteLine("list drive")
srInput.WriteLine("exit")
strResults = srOutput.ReadToEnd
srInput.Close()
srOutput.Close()
Invoke(ShowText)
AND
vb.net Code:
Dim p As Process = Process.Start("diskpart.exe")
'AppActivate(p.MainWindowTitle)
System.Threading.Thread.Sleep(100)
My.Computer.Keyboard.SendKeys("list disk", True)
My.Computer.Keyboard.SendKeys("{ENTER}", True)
This last code, I knew it was not a logical idea so I stopped and never even tried finishing that attempt.