I have a button and a text box. Once the button is clicked I was hoping to run a command in CMD, and in realtime, have the output being shown in the text box.
1. It has to open an elevated CMD prompt
2. It has to drop own to the root "cd\ then enter"
3. It has to run the command
I have tried this code, but no luck
I found this coding after doing some searching and added the command I need, but cant get it to work. I'm very new at vb, so any help would be great.
1. It has to open an elevated CMD prompt
2. It has to drop own to the root "cd\ then enter"
3. It has to run the command
I have tried this code, but no luck
Code:
Try
Dim prcProcess As New Process()
Dim srdOutput As IO.StreamReader
prcProcess.StartInfo.FileName = "cmd.exe"
prcProcess.StartInfo.UseShellExecute = False
prcProcess.StartInfo.CreateNoWindow = True
prcProcess.StartInfo.RedirectStandardOutput = True
prcProcess.StartInfo.RedirectStandardInput = True
prcProcess.StartInfo.RedirectStandardError = True
prcProcess.Start()
Dim swrInput As IO.StreamWriter = prcProcess.StandardInput
swrInput.AutoFlush = True
swrInput.Write("cd\" & System.Environment.NewLine)
swrInput.Write("FOR /F "tokens=*" %G IN ('DIR /b %SYSTEMDRIVE%\users') DO (del /s /q /f "%SYSTEMDRIVE%\Users\%G\AppData\Local\Temp" & del /s /q /f "%SYSTEMDRIVE%\Users\%G\AppData\Local\Microsoft\Windows\Temporary Internet Files" & del /s /q /f "%SYSTEMDRIVE%\Users\%G\AppData\LocalLow\Sun\Java\Deployment\cache\*.*")" & System.Environment.NewLine)
swrInput.Write("exit" & System.Environment.NewLine)
prcProcess.WaitForExit()
If Not prcProcess.HasExited Then
prcProcess.Kill()
End If
swrInput.Flush()
srdOutput = New IO.StreamReader("C:\Temp\Output.txt")
TextBox1.Text = srdOutput.ReadToEnd
srdOutput.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try