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

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
process.Start()
Dim output As String = process.StandardOutput.ReadToEnd()
commented: Thank you! +0

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! :]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.