InvalidOperationException

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I keep getting this error with this line of codeP.BeginOutputReadLine()
full srcPublic Class Form1

Dim P As New Process
Dim SW As System.IO.StreamWriter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("You must have Nmap to use this program. This program can scan your whole network or just the local host.")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = ""

Dim netscan As String

AddHandler P.OutputDataReceived, AddressOf DisplayOutput

AddHandler P.ErrorDataReceived, AddressOf DisplayOutput

P.StartInfo.CreateNoWindow() = True

P.StartInfo.UseShellExecute = False

P.StartInfo.RedirectStandardInput = True

P.StartInfo.RedirectStandardOutput = True

P.StartInfo.RedirectStandardError = True

P.StartInfo.FileName = "nmap.exe"

P.StartInfo.Arguments = "-sP"

If CheckBox1.Checked Then
netscan = InputBox("What is your IPv4? Example: 192.168.2.2")

P.StartInfo.Arguments = netscan

Else

netscan = InputBox("What is your default gateway?", "Network Scan")

P.StartInfo.Arguments = netscan & "/24"

End If

P.Start()

P.SynchronizingObject = TextBox1

P.BeginOutputReadLine()

P.BeginErrorReadLine()

SW = P.StandardInput

SW.WriteLine()

End Sub

Private Sub DisplayOutput(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)

Textbox1.AppendText(output.Data() & vbCrLf)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

TextBox1.Text = ""

Dim netscan As String

AddHandler P.OutputDataReceived, AddressOf DisplayOutput

AddHandler P.ErrorDataReceived, AddressOf DisplayOutput

P.StartInfo.CreateNoWindow() = True

P.StartInfo.UseShellExecute = False

P.StartInfo.RedirectStandardInput = True

P.StartInfo.RedirectStandardOutput = True

P.StartInfo.RedirectStandardError = True

P.StartInfo.FileName = "nmap.exe"

P.StartInfo.Arguments = "-sS -p 1-65535 -T4 -A -v"

If CheckBox1.Checked Then
netscan = InputBox("What is your IPv4? Example: 192.168.2.2")

P.StartInfo.Arguments = netscan

Else

netscan = InputBox("What is your default gateway?", "Network Scan")

P.StartInfo.Arguments = netscan & "/24"

End If

P.Start()

P.SynchronizingObject = TextBox1

P.BeginOutputReadLine()

P.BeginErrorReadLine()

SW = P.StandardInput

SW.WriteLine()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

TextBox1.Text = ""

Dim netos As String

AddHandler P.OutputDataReceived, AddressOf DisplayOutput

AddHandler P.ErrorDataReceived, AddressOf DisplayOutput

P.StartInfo.CreateNoWindow() = True

P.StartInfo.UseShellExecute = False

P.StartInfo.RedirectStandardInput = True

P.StartInfo.RedirectStandardOutput = True

P.StartInfo.RedirectStandardError = True

P.StartInfo.FileName = "nmap.exe"

P.StartInfo.Arguments = "-O"

If CheckBox1.Checked Then
netos = InputBox("What is your IPv4? Example: 192.168.2.2")

P.StartInfo.Arguments = netos

Else

netos = InputBox("What is your default gateway?", "Network Scan")

P.StartInfo.Arguments = netos & "/24"

End If

P.Start()

P.SynchronizingObject = TextBox1

P.BeginOutputReadLine()

P.BeginErrorReadLine()

SW = P.StandardInput

SW.WriteLine()

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

TextBox1.Text = ""

Dim netscan As String

AddHandler P.OutputDataReceived, AddressOf DisplayOutput

AddHandler P.ErrorDataReceived, AddressOf DisplayOutput

P.StartInfo.CreateNoWindow() = True

P.StartInfo.UseShellExecute = False

P.StartInfo.RedirectStandardInput = True

P.StartInfo.RedirectStandardOutput = True

P.StartInfo.RedirectStandardError = True

P.StartInfo.FileName = "nmap.exe"

P.StartInfo.Arguments = "-sS -sU -T4 -O -A -v -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53"

If CheckBox1.Checked Then
netscan = InputBox("What is your IPv4? Example: 192.168.2.2")

P.StartInfo.Arguments = netscan

Else

netscan = InputBox("What is your default gateway?", "Network Scan")

P.StartInfo.Arguments = netscan & "/24"

End If

P.Start()

P.SynchronizingObject = TextBox1

P.BeginOutputReadLine()

P.BeginErrorReadLine()

SW = P.StandardInput

SW.WriteLine()

End Sub
End Class

when i click on one button and have it run the command and it gets all the way done, i move on to the next button and it crashes which is where i get theA first chance exception of type System.InvalidOperationException occurred in System.dll
Error on P.BeingOutputReadLine(), if i click on a button once, its fine but if i click on a total of two buttons even after the first process is completely done, i get this error, idk whats wrong with it.

View the full article
 
Back
Top