Share via

Win32_NetworkAdapter Speed

Sani Love 160 Reputation points
2024-01-09T20:50:57.8733333+00:00

Hello gurus

I'm using Win32_NetworkAdapter and am having trouble showing uint64 Speed to the user in my app.

Need to convert the long bits per second to MegaBit or Gigabit according to the Speed value.

Running the code on my system, I've got these numbers:

9223372036854775807 for Intel Lan

144400000 for Qualcomm WiFi

1000000000 for Private Network

How's the formula and is there some built-in .NET function to east the conversion?

For size, I'd use this, but for bits per second, no idea how to match it to cover all possible values, any help is highly appreciated:

Select Case MySize
    Case 0 To 1023
        Return MySize.ToString + " Bytes"
    Case 1024 To 1048575
        Return (MySize \ 1024).ToString + " KB"
    Case 1048576 To 1073741823
        Return (MySize \ 1048576).ToString + " MB"
    Case 1073741824 To 1099511627775
        Return String.Format("{0:0.00}", MySize / 1073741824) + " GB"
End Select
Developer technologies | VB
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author
  1. Jiachen Li-MSFT 34,241 Reputation points Microsoft External Staff
    2024-01-10T01:50:46.3966667+00:00

    Hi @Sani Love ,

    For the speed in bits per second, you can use the following code to convert it to Kbps, Mbps, or Gbps based on the value.

        Function ConvertSpeedToReadable(speedInBitsPerSecond As ULong) As String
            Dim speed As Double = Convert.ToDouble(speedInBitsPerSecond)
    
            If speed < 1000000 Then
                Return $"{speed / 1000:F2} Kbps"
            ElseIf speed < 1000000000 Then
                Return $"{speed / 1000000:F2} Mbps"
            Else
                Return $"{speed / 1000000000:F2} Gbps"
            End If
        End Function
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.