Results 1 to 5 of 5

Thread: Trying to retrieve current WiFi data usage

  1. #1

    Thread Starter
    New Member Calpgrmr's Avatar
    Join Date
    Nov 2023
    Posts
    9

    Question Trying to retrieve current WiFi data usage

    Greetings,

    After searching and asking ChatGPT, I have cobbled this together:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim q As New ObjectQuery("SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface")
    Dim s As New ManagementObjectSearcher(q)

    For Each mo As ManagementObject In s.Get()
    'show the instance
    Debug.Print(mo.ToString())
    Next

    End Sub


    But I get a runtime error. Does anyone see what I am doing wrong?

    Name:  wifiErr.jpg
Views: 3465
Size:  16.9 KB

  2. #2
    Hyperactive Member
    Join Date
    Jul 2022
    Location
    Buford, Ga USA
    Posts
    506

    Re: Trying to retrieve current WiFi data usage

    I was able to get some information using this:

    Code:
        Private Sub btnGetWifiUsage_Click(sender As Object, e As EventArgs) Handles btnGetWifiUsage.Click
            MessageBox.Show("Your Wi-Fi usage is: " & GetWifiUsage())
        End Sub
    Code:
       Public Function GetWifiUsage() As String
           Dim output As String = ""
           For Each ni As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
               If ni.NetworkInterfaceType = NetworkInterfaceType.Wireless80211 Then
                   Dim stats As IPv4InterfaceStatistics = ni.GetIPv4Statistics()
                   If stats.BytesReceived > 0 Then
                       output += $"Bytes received : {stats.BytesReceived}{vbCrLf}"
                       output += $"Bytes sent: {stats.BytesSent}{vbCrLf}"
                   End If
               End If
           Next
    
           Return output
       End Function
    You need to import
    Code:
    Imports System.Net.NetworkInformation
    Maybe this helps you?

  3. #3

    Thread Starter
    New Member Calpgrmr's Avatar
    Join Date
    Nov 2023
    Posts
    9

    Re: Trying to retrieve current WiFi data usage

    Thank you jdelano !

    I'll give it a try

  4. #4

    Thread Starter
    New Member Calpgrmr's Avatar
    Join Date
    Nov 2023
    Posts
    9

    Resolved Re: Trying to retrieve current WiFi data usage

    GetWifiUsage() works great !

    Thank you so much.

    Cal

  5. #5
    Hyperactive Member
    Join Date
    Jul 2022
    Location
    Buford, Ga USA
    Posts
    506

    Re: Trying to retrieve current WiFi data usage

    Fantastic, glad it worked for you. You're welcome, happy to lend a hand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width