RE: how to execute console commands from form application? 06-20-2011, 08:45 PM
#6
Private Sub readthatthing()
Dim output As String
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
StartInfo.FileName = "cmd" 'starts cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False 'required to redirect
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
SW.WriteLine("ping 192.168.0.1") 'the command you wish to run.....
SW.WriteLine("exit") 'exits command prompt window
output = SR.ReadToEnd 'returns results of the command window
SW.Close()
SR.Close()
MsgBox(output)
End Sub
Dim output As String
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
StartInfo.FileName = "cmd" 'starts cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False 'required to redirect
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
SW.WriteLine("ping 192.168.0.1") 'the command you wish to run.....
SW.WriteLine("exit") 'exits command prompt window
output = SR.ReadToEnd 'returns results of the command window
SW.Close()
SR.Close()
MsgBox(output)
End Sub




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)