在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
代码如下:
/// <summary>
/// 获取系统内存大小 /// </summary> /// <returns>内存大小(单位M)</returns> private static int GetPhisicalMemory() { ManagementObjectSearcher searcher = new ManagementObjectSearcher(); //用于查询一些如系统信息的管理对象 searcher.Query = new SelectQuery("Win32_PhysicalMemory ", "", new string[] { "Capacity" });//设置查询条件 ManagementObjectCollection collection = searcher.Get(); //获取内存容量 ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator(); long capacity = 0; while (em.MoveNext()) { ManagementBaseObject baseObj = em.Current; if (baseObj.Properties["Capacity"].Value != null) { try { capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString()); } catch { return 0; } } } return (int)(capacity / 1024 / 1024); } |
请发表评论