views:

25

answers:

1

Hello 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? Reason being is i have this 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...

A: 

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);
    }
}
Jack B Nimble