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
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