问题描述
有没有办法通过WMI查询在C#中一样,你可以用 System.Diagnostics.PerformanceCounter
类呢?
Is there a way to query via WMI in C# like you can do with the System.Diagnostics.PerformanceCounter
class?
简单地说我怎么可以通过它像字符串\\本地主机\处理器(0)\%处理器时间
,这将构建正确的WMI查询我吗?
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.
推荐答案
您可以使用WMI的的。这方面的一个例子是轮询PerfDisk_LogicalDisk
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);
}
}
这篇关于WMI性能计数器查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!