问题描述
我需要从本地和远程计算机上检索RAM信息,我知道System.Management中的WMI,并且正在使用它,但是WMI的问题是Win32_PhysicalMemory类具有我需要的值 strong> MemoryType ,但它始终返回0或未知。
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,并且使用admin帐户和返回相同的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.
Am我错误地使用了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类为我提供了所有这些信息,除了RAM类型。
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信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!