怎么获取不了内存啊!
ManagementObjectSearcher mos = new ManagementObjectSearcher();
mos.Query = new SelectQuery( "Win32_PhysicalMemory ", " ", new string[] { "Capacity " });//设置查询条件
ManagementObjectCollection moc = mos.Get();
ManagementObjectCollection.ManagementObjectEnumerator em = moc.GetEnumerator();
int capacity = 0;
while (em.MoveNext())
{
ManagementBaseObject baseObj = em.Current;
if (baseObj.Properties[ "Capacity "].Value != null)
{
try
{
capacity += int.Parse(baseObj.Properties[ "Capacity "].Value.ToString());
}
catch
{
// MessageBox.Show( "有错误发生!\n ", "错误信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return 0;
}
}
}
return capacity;
[解决办法]
[解决办法]
[解决办法]
[解决办法]