WMI 硬件,获取 RAM 信息 [英] WMI hardware, get RAM info

查看:38
本文介绍了WMI 硬件,获取 RAM 信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从本地和远程计算机检索 RAM 信息,我知道 System.Management 中的 WMI 并且我正在使用它,但我的 WMI 问题是 Win32_PhysicalMemory 类有一个我需要调用的值MemoryType",但它始终返回 0 或未知".
Win32_PhysicalMemory 类 (http://msdn.microsoft.com/en-us/library/aa394347%28v=vs.85%29.aspx)

I need to retrieve RAM info from both local and remote computers, I am aware of WMI in System.Management and I am using it, but my problem with WMI is that the Win32_PhysicalMemory class has a value that I need called "MemoryType", but it always returns 0 or "Unknown".
Win32_PhysicalMemory class (http://msdn.microsoft.com/en-us/library/aa394347%28v=vs.85%29.aspx)

我尝试在 3 台不同的 XP Professional 计算机上使用 C# 和 VBScript 中的 Win32_PhysicalMemory 使用管理员帐户并返回相同的 0 或未知"MemoryType 值.我使用的代码简单而简短,是从网络上的许多来源复制粘贴的,所以我确信它没有大问题.

I have tried to use Win32_PhysicalMemory from both C# and VBScript on 3 different XP Professional computers with an admin account and got the same 0 or "Unknown" MemoryType value returned. The code I used is simple and short, copy and pasted from a number of sources around the net so I'm sure there aren't major problems with it.

我是否错误地使用了 WMI 或者是否有我可以使用的 Windows API 替代方案?
远程报告不是必需的.

Am I using WMI wrongly or is there a Windows API alternative i can use?
Remote reports aren't essential.

具体来说,我需要计算它拥有或可以拥有的 RAM 条数、速度以及它使用的 RAM 类型,DDR2、DDR3 等,Win32_PhysicalMemory 类为我提供了所有这些,除了类型内存.

Specifically I need to count the number of sticks of RAM it has, or can have, the speed, and the type of RAM it uses, DDR2, DDR3, etc., the Win32_PhysicalMemory class gives me all this except the type of RAM.

ConnectionOptions connection = new ConnectionOptions();
connection.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope scope = new ManagementScope("\\.\root\CIMV2", connection);                
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())
{
    System.Diagnostics.Debug.WriteLine("-----------------------------------");
    System.Diagnostics.Debug.WriteLine("Capacity: {0}", queryObj["Capacity"]);
    System.Diagnostics.Debug.WriteLine("MemoryType: {0}", queryObj["MemoryType"]);
}

推荐答案

根据这篇知识库文章,某些类型的内存将被列为未知,因为它当时不在 SMBIOS(WMI 使用的)中.显然从那以后它就没有更新了.它说它适用于 Windows Server 2003,但我在 Windows 7 x64 上看到了相同的结果.

According to this kb article, certain types of memory will be listed as unknown since it wasn't in the SMBIOS (which WMI uses) at the time. Apparently it hasn't been updated since then. It says it applies to Windows Server 2003 but I see the same results on Windows 7 x64.

我想解决这个问题,你可以去掉中间人,不使用 WMI,而是直接使用 SMBIOS.我在那里不会有太大帮助,但至少它会给你一个前进的方向.

I suppose to get around this, you can cut the middle man and not use WMI but use the SMBIOS directly. I won't be of much help there but at least it will give you a direction to go on.

这篇关于WMI 硬件,获取 RAM 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆