Performing a ping from within VB.Net

  • Thread starter Thread starter Raf
  • Start date Start date
R

Raf

Hello to the pros,

I have to create an application that performs a "Ping" to an IP-address. The
result (successfull or not successfull)
should be captured by the application and should be shown to the user.

I know that you can perform dos-commands with the SHELL-command.
But is there a possibility to catch the result of this ping-command if I do
it like this.

Does anyone have some suggestions?

Thanks in advance,

Regards,
 
Hi, Raf

you can do this. Recently people discussed here redirection and capture of
dos commands results - Shell() -? posts.
Thanks to Henry Craven - you can try this sample code - just change called
program and arguments:

Dim ProcID As Integer

Dim sSource As String = "D:\Data\Test"

Dim sDest As String = "D:\VB"

Dim sShell As String = "E:\winnt\System32\xcopy.exe"

Dim s As String = ""

'Try

Dim p As New Process

p.StartInfo.UseShellExecute = False

p.StartInfo.RedirectStandardOutput = True

p.StartInfo.Arguments = "D:\Data\Test D:\VB /e /d /h /o /v"

p.StartInfo.WorkingDirectory = "E:\winnt\system32"

p.StartInfo.FileName = "xcopy"

p.Start()

Dim sr As IO.StreamReader = p.StandardOutput

Dim sb As New System.Text.StringBuilder("")

Dim sinput As String = ""

Do Until sinput = "-1"

sb.Append(sr.ReadLine() & ControlChars.CrLf)

sinput = sr.Read

Loop

Dim sw As New IO.StreamWriter("C:\test2.txt")

sw.Write(sb.ToString)

Me.Close()
 
Back
Top