BlackTea
BlackTea

Reputation: 294

WMI Performance counter Query issues

Is there a way to query via WMI in C# like you can do with the System.Diagnostics.PerformanceCounter class?

Simply put how can I pass it a string like \\localhost\Processor(0)\% Processor Time and it would build the correct WMI query for me?

I have huge list of counters in a flat file from a legacy program and I want to move it to a Service which just runs through the flat file and gets the value.

Upvotes: 2

Views: 2276

Answers (1)

Jack B Nimble
Jack B Nimble

Reputation: 5087

You can use the WMI Performance Class Counters. An example of this would be polling the PerfDisk_LogicalDisk

ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk");
foreach (ManagementObject service in mos.Get())
{
    foreach (PropertyData data in service.Properties)
    {
        Console.WriteLine("{0} {1}", data.Name, data.Value);
    }
}

Upvotes: 2

Related Questions