Link to home
Start Free TrialLog in
Avatar of rae_rae
rae_raeFlag for United States of America

asked on

Visual basic routine...having trouble...

   Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        If NetstatCheckBox.Checked = True Then
            ' Set Timer to loop forever and viewerLabel.Text to display results
            Dim intTimer As Integer
            intTimer = 0
            Do While intTimer = -1
                Me.ViewerLabel.Text = Shell("C:\WINDOWS\System32\netstat.exe")
            Loop
        End If
    End Sub

What's wrong with my code? It should display the results of netstat in Me.ViewerLable.Text...
Avatar of riaancornelius
riaancornelius

Shell("C:\WINDOWS\System32\netstat.exe") will simply execute the netstat app in a cmd shell, and probably returns an int (status code when it exits). I don't think you can get the shell to return the text to your app.
Avatar of Mike Tomlinson
Something like...

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        If NetstatCheckBox.Checked = True Then
            Dim p As New Process
            p.StartInfo.UseShellExecute = False
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.FileName = "C:\WINDOWS\System32\netstat.exe"
            p.Start()
            Me.ViewerLabel.Text = p.StandardOutput.ReadToEnd()
            p.WaitForExit()
        End If
    End Sub
this code:

            ' Set Timer to loop forever and viewerLabel.Text to display results
            Dim intTimer As Integer
            intTimer = 0
            Do While intTimer = -1
                Me.ViewerLabel.Text = Shell("C:\WINDOWS\System32\netstat.exe")
            Loop


does NOT affect a timer object in any way.  IntTimer is a variable that you set to 0, but it NEVER CHANGES, so when you get to the next line (Do While intTimer = -1), intTimer has the value 0, so the loop immediately terminated, since intTimer is NOT equal to -1 (you just set it to 0!!!!)

You do not appear to have a Timer object in your program???

AW


What are you really trying to do, get the output from a command line program or display the network statistics (netstat). If you are trying to get the network statistics then check out this cool ip helper api wrapper

http://www.codeproject.com/vb/net/netstat.asp 

yea its another source code site but hey the implementation is pretty simple ;)

Good Luck
Avatar of rae_rae

ASKER

Ok i have:
    Private Sub StartButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        Dim UserChoice As Boolean
        If NetstatCheckBox.Checked And Not TracertCheckBox.Checked = True And Not NetTraceCheckBox.Checked = True Then
            Dim p As New Process
            p.StartInfo.UseShellExecute = False
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.FileName = "C:\WINDOWS\System32\netstat.exe"
            p.Start()
            Me.ViewerTextBox.Text = p.StandardOutput.ReadToEnd()
            p.WaitForExit()
        ElseIf TracertCheckBox.Checked = True And NetTraceCheckBox.Checked = True Then
            Call SelectionError()
        ElseIf NetstatCheckBox.Checked = True And TracertCheckBox.Checked = True Then
            Call SelectionError()
        ElseIf NetstatCheckBox.Checked = True And NetTraceCheckBox.Checked = True Then
            Call SelectionError()
        ElseIf TracertCheckBox.Checked = True Then
            Me.ViewerTextBox.Text = ""
            MsgBox("Function not yet implimented", MsgBoxStyle.Information, "Tracert Function")
        ElseIf NetTraceCheckBox.Checked = True Then
            Me.ViewerTextBox.Text = ""
            MsgBox("Functions not yet implimented", MsgBoxStyle.Information, "Combo Functions")
        Else
            Me.ViewerTextBox.Text = "Please make any single selection"
        End If

    End Sub
    Private Sub SelectionError()
        Me.ViewerTextBox.Text = "Please make only one selection"
    End Sub

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Me.ViewerTextBox.Text = "Ready..."

    End Sub
But it's not formatting my data very well...
I'm sure it's cuz i'm just a beginner.
>> But it's not formatting my data very well...

What exactly do you want formatted and how?

Are the results netstat.exe making it to ViewerTextBox with the code I gave you?
Avatar of rae_rae

ASKER

http://www.pirateculture.net/Downloads/NetStat.zip
That's where the source code is...
I guess what i want it to do is for the Viewer.TextBox.Text to be able to scroll...
This isn't entirely necessary, but it would be nice.
I'd prefer it if the output didn't scroll sideways. But the one thing i want for sure is for the window to refresh every so often...
I don't suppose that it matters much how often. I did try to put the code in a loop but it ran so many instances of %systemroot%\system32\netstat.exe that it wasn't possible to see what was happening in the netstat window...it was an imidiate loop though.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rae_rae

ASKER

Thanks a ton !
We could sure use some more programmers on our sites if you're ever interested...
www.pirateculture.net and www.skynet-systems.com
Again, thanks!