Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Network Speed 1

Status
Not open for further replies.

schwarem

Programmer
Apr 18, 2002
159
0
0
US
I am looking for code to detect the speed of uploads and downloads for my network connection in VB.net. I want to monitor the speed and use more processes if the speed is high enough.
 
There are quite a few ways to get the network speed, here's a WMI example that retrieves the bytes per seconds:
Code:
Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

    Public Class MyWMIQuery

        Public Overloads Shared Function Main() As Integer

            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface") 

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_PerfFormattedData_Tcpip_NetworkInterface instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("BytesReceivedPersec: {0}", queryObj("BytesReceivedPersec"))
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function
    End Class
End Namespace

 
I tried this, but I always get zero for my speed.
 
I copied the code to a class, removed the console.writeline statements. set the main method to return an integer value of queryObj. Created a reference to System.Management. Placed a timer and 2 labels on the form. Declared a private field to keep track of the total. Set the timer interval to 1000. Called the main method from the timer and it is working fine for me. Is WMI running on you computer?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top