【发布时间】:2011-07-30 19:58:49
【问题描述】:
我正在尝试确定计算机中安装的物理内存量。为了实现这一点,我正在使用 WMI(通过 .net 4.0)及其服务。问题是无论远程计算机有多少内存,返回的值都是 4GB。这已经在三台远程计算机上进行了测试:
- 虚拟机,1GB RAM,Windows 2003
- 物理机,2GB RAM,Windows XP
- 物理机,2GB RAM,Windows 7 64bit
我自己正在运行物理机,4GB RAM,Windows 7 64bit。
显示代码:
uint phisicalMemorySize = 0;
ConnectionOptions co = new ConnectionOptions();
co.Username = null;
ManagementScope ms = new ManagementScope("\\\\" + computerName, co);
ObjectQuery q = new ObjectQuery("select TotalPhysicalMemory from Win32_ComputerSystem");
ManagementObjectSearcher os = new ManagementObjectSearcher(ms, q);
ManagementObjectCollection moc = os.Get();
foreach (ManagementObject o in moc)
{
phisicalMemorySize += Convert.ToUInt64(o["TotalPhysicalMemory"], CultureInfo.InvariantCulture);
}
我也尝试过使用select Capacity from Win32_PhysicalMemory
和select TotalVisibleMemorySize from Win32_OperatingSystemas 查询但无济于事。最后phisicalMemorySize 总是4GB。
【问题讨论】: