【发布时间】:2016-10-09 04:17:32
【问题描述】:
我正在编写一个 WMI 提供程序,并且我设法检索了有关 计算机系统和硬件类 的所有信息,但无法从 获取我想要的数据>性能计数器类。 (Win32 Classes)
查看 MSDN 文档并使用它们提供的示例,我想出了一个 shell 脚本,它应该返回 Win32_PerfFormattedData 抽象基类的所有属性。
脚本:
$osClass = New-Object System.Management.ManagementClass Win32_PerfFormattedData
$osClass.Options.UseAmendedQualifiers = $true
# Get the Properties in the class
$properties = $osClass.Properties
"This class has {0} properties as follows:" -f $properties.count
# display the Property name, description, type, qualifiers and instance values
foreach ($property in $properties) {
"Property Name: {0}" -f $property.Name
"Description: {0}" -f $($property.Qualifiers["Description"].Value)
"Type: {0}" -f $property.Type
"-------"
}
(引用自here)
问题是我只从它的基类Win32_Perf检索属性
编辑
经过更多研究,我在 MSDN 上找到了这个:
计数器对象的 WMI 格式类名称的格式为 "Win32_PerfFormattedData_service_name_object_name"
我正在尝试获取 Win32_PerfFormattedData 中的 service_name 以及这些服务中的 object_name。
我不确定获取属性是否是我现在想要的方式,但我找不到任何文档来获取服务。它们是一样的吗?如果没有,我怎样才能获得我需要的信息? (service_name 的 & object_name 的)
我也在一些 C# 代码中尝试过这个并得到相同的结果:
ManagementClass processClass = new ManagementClass();
processClass.Path = new ManagementPath("Win32_PerfFormattedData");
PropertyDataCollection properties = processClass.Properties;
Console.WriteLine("\nProperties:");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
我尝试检索 方法 以检查这是否是我想要的,但没有返回任何内容:
Console.WriteLine("Methods: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
编辑 2
还有其他方法可以检索这些数据吗?我浏览了有关 WMI 的 MSDN 文档,我认为要获得我想要的信息,我必须访问该类 (Win32_PerfFormattedData)。我要检索的各种值:
- CPU
- 内存
- 驱动器(SSD/HDD)
- 流程
- 操作系统
- GPU
我检索了一些类,它们将提供有关其中一些的基本信息,但不会提供有关每个逻辑处理器的温度等最新数据。我已经设法从类 Win32_PerfFormattedData_PerfOS_Processor 中获得 1 个服务,该类提供每个逻辑处理器的负载百分比,但该类必须包含我需要的其他服务。
【问题讨论】:
标签: c# powershell wmi