Hello everyone. I am working on a simple program called "Who's Connected?" where it runs a command (netstat -aon) and then displays the results in a multi-lined textbox. However, when I press the button that will run the command, it tells me that it can't convert the string to an integer or something. And when I did manage to get it to convert to an integer, it really showed an integer in the textbox instead of the connections and IP addresses. What do I do? Here is the code I have:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Running command and displaying results in textbox1
        TextBox1.Text = CStr(Shell("netstat -aon"))
        'Results end up being a triple or quadruple digit number
    End Sub
6 Years
Discussion Span
Last Post by The 7331 Geek

The number is a process ID of the still running command, what i am going to give you is untested, but the idea is there. try something like this

Dim process As New Process()
Dim FileName As String = "netstat"
Dim Arguments As String = "-aon"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.StartInfo.FileName = FileName
process.StartInfo.Arguments = Arguments
process.StartInfo.WorkingDirectory = WorkingDirectory
Dim output As String = process.StandardOutput.ReadToEnd()
Votes + Comments
Thank you!

It worked! All I had to add after that was

TextBox1.Text = output

and it worked like a charm.
I did have to remove "process.StartInfo.WorkingDirectory = WorkingDirectory" because it wasn't declared, but everything still seems to be working.
Thanks! :]

This question has already been answered. 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.