How to create mutliple instances of Tracert in VB.NET to run at thesame time

W

whitethomas12

Hi,

I currently have some basic code that allows me to run the tracert
command through VB.NET and it also updates my database based on the
results.


I was wondering if someone can help me find a way that I can used my
code to run tracert on mutiple instances at the same time. The
following is my current code.


Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
' start NT tracert command
Dim ExeFileName As String
Dim Arguments As String
ExeFileName = "tracert"
Arguments = txtRoute.Text & " -h 5"
Dim s As String
Dim p As New Process
With p.StartInfo
.WorkingDirectory = "C:\windows\system32"
.FileName = ExeFileName
.Arguments = Arguments
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
End With
Try
p.Start()
s = p.StandardOutput.ReadToEnd()
p.WaitForExit()
Catch ex As Exception
s = ex.ToString
End Try
p.Dispose()
Dim test As String
Dim r As Integer
Dim rtimout As Single
Dim sever As Single
Dim devicname As String
Dim alrstr As String
'Determine Link State
rtimout = 0
test = s.ToString
r = test.IndexOf("192.168.101.2")
If r > 0 Then
lblStatus.Text = "STATUS: Link to CORP is FSO"
sever = 1
devicname = "FSO"
alrstr = "Primary Route FSO is UP"
SqlSelectInsert(sever, devicname, alrstr)
ElseIf Not r > 0 Then
r = test.IndexOf("192.168.11.21")
If r > 0 Then
lblStatus.Text = "STATUS: Link to Site1 is Router1"
sever = 2
devicname = "Radio"
alrstr = "Secondary Route is UP, Primary Route is
down"
SqlSelectInsert(sever, devicname, alrstr)
ElseIf Not r > 0 Then
r = test.IndexOf("timed out")
lblStatus.Text = "STATUS: Link is Down"
If r > 0 Then
sever = 3
devicname = "NetworkDown"
alrstr = "The Network is Down
SqlSelectInsert(sever, devicname, alrstr)
End If
End If
End If
'MessageBox.Show(s.ToString())
End Sub
Public Function SqlSelectInsert(ByVal sever As String, ByVal
devicname As String, ByVal alrstr As String) As String
'Create SQL Connection
Dim sqlResult As String
Dim sqlCon As New System.Data.SqlClient.SqlConnection
Dim sConnStr As String
sConnStr = "server=myserver
\nmssse;uid=test;pwd=test12345;database=test_Database"
sqlCon.ConnectionString = sConnStr
' Query the database before making and entry
sqlCon.Open()
Dim sqlcommand As New System.Data.SqlClient.SqlCommand
sqlcommand.CommandType = CommandType.StoredProcedure
sqlcommand.CommandText = "dbo.Select_LastRouteEntry"
sqlcommand.Connection = sqlCon
Dim sqlDataReader As System.Data.SqlClient.SqlDataReader
sqlDataReader = sqlcommand.ExecuteReader
If sqlDataReader.HasRows Then
While sqlDataReader.Read
sqlResult =
sqlDataReader.GetString(sqlDataReader.GetOrdinal("devname"))
End While
End If
sqlCon.Close()
If Not devicname = sqlResult Then
sqlCon.Open()
Dim sqlCommand2 As New System.Data.SqlClient.SqlCommand
sqlCommand2.CommandType = CommandType.StoredProcedure
sqlCommand2.CommandText = "dbo.Insert_Route_Info"
sqlCommand2.Connection = sqlCon
sqlCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@sever", sever))
sqlCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@devname", devicname))
sqlCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@alrstr", alrstr))
sqlCommand2.ExecuteNonQuery()
sqlCon.Close()
End If
Return True
End Function


Thank you in advance
 
W

whitethomas12

Hi,

I currently have some basic code that allows me to run the tracert
command through VB.NET and it also updates my database based on the
results.

I was wondering if someone can help me find a way that I can used my
code to run tracert on mutiple instances at the same time.  The
following is my current code.

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
        ' start NT tracert command
        Dim ExeFileName As String
        Dim Arguments As String
        ExeFileName = "tracert"
        Arguments = txtRoute.Text & " -h 5"
        Dim s As String
        Dim p As New Process
        With p.StartInfo
            .WorkingDirectory = "C:\windows\system32"
            .FileName = ExeFileName
            .Arguments = Arguments
            .UseShellExecute = False
            .RedirectStandardError = True
            .RedirectStandardInput = True
            .RedirectStandardOutput = True
            .WindowStyle = ProcessWindowStyle.Hidden
            .CreateNoWindow = True
        End With
        Try
            p.Start()
            s = p.StandardOutput.ReadToEnd()
            p.WaitForExit()
        Catch ex As Exception
            s = ex.ToString
        End Try
        p.Dispose()
        Dim test As String
        Dim r As Integer
        Dim rtimout As Single
        Dim sever As Single
        Dim devicname As String
        Dim alrstr As String
        'Determine Link State
        rtimout = 0
        test = s.ToString
        r = test.IndexOf("192.168.101.2")
        If r > 0 Then
            lblStatus.Text = "STATUS: Link to CORP is FSO"
            sever = 1
            devicname = "FSO"
            alrstr = "Primary Route FSO is UP"
            SqlSelectInsert(sever, devicname, alrstr)
        ElseIf Not r > 0 Then
            r = test.IndexOf("192.168.11.21")
            If r > 0 Then
                lblStatus.Text = "STATUS: Link to Site1 is Router1"
                sever = 2
                devicname = "Radio"
                alrstr = "Secondary Route is UP, PrimaryRoute is
down"
                SqlSelectInsert(sever, devicname, alrstr)
            ElseIf Not r > 0 Then
                r = test.IndexOf("timed out")
                lblStatus.Text = "STATUS: Link is Down"
                If r > 0 Then
                    sever = 3
                    devicname = "NetworkDown"
                    alrstr = "The Network is Down
                    SqlSelectInsert(sever, devicname, alrstr)
                End If
            End If
        End If
        'MessageBox.Show(s.ToString())
    End Sub
    Public Function SqlSelectInsert(ByVal sever As String, ByVal
devicname As String, ByVal alrstr As String) As String
        'Create SQL Connection
        Dim sqlResult As String
        Dim sqlCon As New System.Data.SqlClient.SqlConnection
        Dim sConnStr As String
        sConnStr = "server=myserver
\nmssse;uid=test;pwd=test12345;database=test_Database"
        sqlCon.ConnectionString = sConnStr
        ' Query the database before making and entry
        sqlCon.Open()
        Dim sqlcommand As New System.Data.SqlClient.SqlCommand
        sqlcommand.CommandType = CommandType.StoredProcedure
        sqlcommand.CommandText = "dbo.Select_LastRouteEntry"
        sqlcommand.Connection = sqlCon
        Dim sqlDataReader As System.Data.SqlClient.SqlDataReader
        sqlDataReader = sqlcommand.ExecuteReader
        If sqlDataReader.HasRows Then
            While sqlDataReader.Read
                sqlResult =
sqlDataReader.GetString(sqlDataReader.GetOrdinal("devname"))
            End While
        End If
        sqlCon.Close()
        If Not devicname = sqlResult Then
            sqlCon.Open()
            Dim sqlCommand2 As New System.Data.SqlClient.SqlCommand
            sqlCommand2.CommandType = CommandType.StoredProcedure
            sqlCommand2.CommandText = "dbo.Insert_Route_Info"
            sqlCommand2.Connection = sqlCon
            sqlCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@sever", sever))
            sqlCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@devname", devicname))
            sqlCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@alrstr", alrstr))
            sqlCommand2.ExecuteNonQuery()
            sqlCon.Close()
        End If
        Return True
    End Function

Thank you in advance

HI,

After thinking about my request, I thinking that maybe utilizing
timers will work but I am unsure on how to do it to allow it to be
dynamic. What I mean by dydnamic is to allow an end user to select a
property and then set how the laps time between each instance. Some
instances should be able to run at the same time while others on
different times. For example:

1. Route 1 is checked every minute
2. Route 2 is also checked every minute
3. Route 3 is checked every 5 minutes

Is it possible that someone can post some sample code to just get me
started. It would be greatly appreciated

Thank You
 
W

whitethomas12

HI,

After thinking about my request, I thinking that maybe utilizing
timers will work but I am unsure on how to do it to allow it to be
dynamic. What I mean by dydnamic is to allow an end user to select a
property and then set how the laps time between each instance.  Some
instances should be able to run at the same time while others on
different times.  For example:

1.  Route 1 is checked every minute
2. Route 2 is also checked every minute
3.  Route 3 is checked every 5 minutes

Is it possible that someone can post some sample code to just get me
started.  It would be greatly appreciated

Thank You- Hide quoted text -

- Show quoted text -

P.S. My project is database driven so the number of objects can
change...Please help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top