简体   繁体   中英

C# Using WMI To Query LogicalDisk Information

I'm looking to get performance information for the disks on my local computer using WMI. According to the documentation for Win32_PerfFormattedData_PerfDisk_LogicalDisk (http://msdn.microsoft.com/en-us/library/aa394261(v=vs.85).aspx), it looks like I should just be able to query the information and get the values.

However, when I run the code I get "0" for each value for the properties.

var selectQuery = new SelectQuery("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk");
var searcher = new ManagementObjectSearcher(selectQuery);

foreach (ManagementObject disk in searcher.Get())
{
    foreach (PropertyData property in disk.Properties)
    {
        var propertyValue = property.Value; // 0 value.
    }
}

I have also queried Win32_PerfRawData_PerfDisk_LogicalDisk and I do get actual raw values. Of course, I would rather have the formatted data instead of the raw data. The documentation for converting the raw data to the formatted data seems to be lacking when it comes to using WMI.

Any idea why I am getting 0 for each value?

Here is a working example just tested this

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 propData in service.Properties)
    {
        Console.WriteLine("{0} {1}", propData.Name, propData.Value);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM