Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

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...
0
rae_rae
Asked:
rae_rae
1 Solution
 
riaancorneliusCommented:
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
Arthur_WoodCommented:
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


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kurtnelleCommented:
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
0
 
rae_raeAuthor Commented:
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> 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?
0
 
rae_raeAuthor Commented:
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> 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.

Set the MultiLine property of the TextBox to true and set the ScrollBars property to Vertical.

>> But the one thing i want for sure is for the window to refresh every so often...

Add a Timer control to your form and set its Interval property to "every so often".  An interval of 5000 will make it fire every 5 seconds:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim p As New Process
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.FileName = "C:\WINDOWS\System32\netstat.exe"
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        p.Start()
        Me.TextBox1.Text = p.StandardOutput.ReadToEnd()
        p.WaitForExit()
    End Sub
0
 
rae_raeAuthor Commented:
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!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now