在程序中,调用WMI的时候,出现一个问题,就是我系统有插了两条内存条,共4G。然而自己只能在程序中查到安装内存为2G,感觉有点不淡定。这是之前的代码。

   static ManagementObjectSearcher PhysicalMemory = new ManagementObjectSearcher("select * from Win32_PhysicalMemory");

     // 安装内存
    string hd = strInstalledMemory + String.Format("{0} GB", Convert.ToInt64(GetValue(PhysicalMemory, "Capacity")) / 1024 / 1024 / 1024);

   static object GetValue(ManagementObjectSearcher searcher, string propName)

   {
     foreach (ManagementObject mobj in searcher.Get())
     return mobj[propName];
    throw new NotSupportedException();
    }

 

    这个明显是不完整的,并没有查询到所有的内存,多个内存条的话,就不行了。然后我改进了下:

    //获取安装内存大小

          
     }
       moc1.Dispose();
      cimobject1.Dispose();

       hd = "安装内存:"+ capacity + "G";

     这样就搞定了。水平有限,如有更好的方法,求分享。。

  

相关文章:

  • 1970-01-01
  • 2022-12-23
  • 2021-09-27
  • 2022-02-09
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2023-02-14
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2021-12-12
相关资源
相似解决方案