I try to read out WMI data with C#. I use the System.Management namespace. For the most WMI-Queries it works quiet good. But when I try to read "BytesTotalPerSec" from Win32_PerfFormattedData_Tcpip_NetworkInterface it doesn't work. My code looks like this:
var select = $"SELECT BytesTotalPerSec FROM
Win32_PerfFormattedData_Tcpip_NetworkInterface WHERE Name = 'MyAdapter'";
var scope = new ManagementScope($"\\\\{computername}\\root\\cimv2");
scope.Connect();
var query = new ObjectQuery(select);
var searcher = new ManagementObjectSearcher(scope, query);
var queryCollection = searcher.Get();
double value = 0;
foreach (var item in queryCollection)
value = Convert.ToDouble(item["BytesTotalPerSec"]);
I tried this code with other WMI-Queries and it works. When I debug the code, the queryCollection has no items. Does anyone know what I'm doing wrong?
Sorry for my bad english, I hope you understand my Problem.