How to determine the bandwidth in Windows 7, 8.1 and 10?

So far I have been trying to work with MbnInterfaceManager (see hresult from IMbnInterfaceManager :: GetInterfaces when there is no MBN device ), so instead I built and debug the application without problems from Visual Studio 2015 that executed this WMI request in C # (see also Win32_PerfFormattedData_Tcpip_NetworkInterface documentation ):

 string query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; ManagementObjectSearcher moSearch = new ManagementObjectSearcher(query); ManagementObjectCollection moCollection = moSearch.Get(); 

But then, when I deployed the application on Windows 8.1, I get this error every time the request is executed:

 System.Management.ManagementException: Invalid query at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() 

Does anyone have any suggestions to fix this problem? How can I deploy the application so that it can use such requests?

UPDATE:

Please note that I can create and run the above code (as part of a larger WPF application) from Visual Studio 2015 on Windows 7 or Windows 8.1, and I can deploy this application using ClickOnce on Windows 7, where it works successfully. For some reason, when I deploy this application using ClickOnce on Windows 8.1, I get an Invalid query message.

0
source share
1 answer

I think what I need to do is to make sure that the System.Management link is set to Copy Local, but I can’t check it right now. If anyone has any better ideas, please feel free to let me know.

UPDATE:

You cannot use System.Management.dll in Windows 8.1 in the same way that it is used in Windows 7 or Windows 10.

I found that to perform operations similar to those that I mentioned in my question on Windows 8.1 and Windows 8, you need to either obtain a Windows 8.1 developer license or set the computer to "Developer Mode" on Windows 10, so you can use the space Windows.Networking.Connectivity Names:

  string connectionProfileInfo = string.Empty; ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (InternetConnectionProfile == null) { rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage); } else { connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile); OutputText.Text = connectionProfileInfo; rootPage.NotifyUser("Success", NotifyType.StatusMessage); } // Which calls this function, that allows you to determine how strong the signal is and the associated bandwidth string GetConnectionProfile(ConnectionProfile connectionProfile) { // ... if (connectionProfile.GetSignalBars().HasValue) { connectionProfileInfo += "====================\n"; connectionProfileInfo += "Signal Bars: " + connectionProfile.GetSignalBars() + "\n"; } // ... } 

Please note that you must ensure that your project is a Windows 8.1 PCL or a Windows 8.1 application in order to be able to reference the namespace.

See https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201 for details

UPDATE 2:

To get the bandwidth in Windows 7, 8.1 and 10, I ended up using this code:

  private int GetMaxBandwidth() { int maxBandwidth = 0; NetworkInterface[] networkIntrInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (var networkInterface in networkIntrInterfaces) { IPv4InterfaceStatistics interfaceStats = networkInterface.GetIPv4Statistics(); int bytesSentSpeed = (int)(interfaceStats.BytesSent); int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived); if (bytesSentSpeed + bytesReceivedSpeed > maxBandwidth) { maxBandwidth = bytesSentSpeed + bytesReceivedSpeed; } } } 
0
source

Source: https://habr.com/ru/post/1241730/


All Articles