-
Dec 1st, 2023, 11:16 AM
#1
Thread Starter
New Member
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?
-
Dec 2nd, 2023, 07:45 AM
#2
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?
-
Dec 2nd, 2023, 08:03 AM
#3
Thread Starter
New Member
Re: Trying to retrieve current WiFi data usage
Thank you jdelano !
I'll give it a try
-
Dec 2nd, 2023, 08:55 AM
#4
Thread Starter
New Member
Re: Trying to retrieve current WiFi data usage
GetWifiUsage() works great !
Thank you so much.
Cal
-
Dec 2nd, 2023, 09:23 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|