Hello. I have two forms. Let's call them form1 and form2. Form1 is a form which controls the meat of my program and runs in the background. Form2 is a popup-like dialog that will pop up when triggered by an event in form1.

I want to call the netstat command from a cmd process. That part is not hard. I have a stream writer piping the commands into the command prompt process, and a stream reader reading back the contents of the window. What I would like to have happen is to have a loop which loops the netstat command. Every time that the contents of the netstat window changes, I would like the output to be displayed in a listbox in form2. So, form2 will only show up when the netstat process spits back new text.

Also, if possible, I would like to have the form2 only display the new information from the netstat command line, and not all of the standard command prompt jargon. I think that I would need to trim the output stream, but I'm not sure. If this isn't possible, that's ok, but I would like to have the form2 monitor the netstat process and popup anytime the text in the netstat window changes. Thanks!!!

P.S. - If you don't know what netstat is, it is a command you run from a command prompt (:cheesy:), which displays all active ports on your computer. To try it, go to a command prompt and type netstat.

10 Years
Discussion Span
Last Post by waynespangler

Here's how you would redirect the output to a textbox.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Proc As Process = New Process
        Proc.StartInfo.FileName = "netstat.exe"
        Proc.StartInfo.UseShellExecute = False
        Proc.StartInfo.RedirectStandardOutput = True
        Proc.StartInfo.CreateNoWindow = True
        ' This redirects the output to the textbox
        TextBox1.Text = Proc.StandardOutput.ReadToEnd
    End Sub

I leave it to you to get this textbox to a listbox. Possibably using split command.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.