/// <summary> /// Retrieve RAM information /// </summary> /// <returns>A list of RamStick objects</returns> internal static List <RamStick> GetRamSticks() { List <RamStick> ramSticks = new List <RamStick>(); ConnectionOptions connection = new ConnectionOptions { 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); // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop foreach (ManagementObject queryObj in searcher.Get()) { RamStick stick = new RamStick(); foreach (PropertyData data in queryObj.Properties) { if (data.Value != null) { stick.AddRamData(new RamData(data.Name, data.Value.ToString())); } } ramSticks.Add(stick); } return(ramSticks); }
/// <summary> /// Export a list of RamStick objects to a specific path in HTML format /// </summary> /// <param name="path">The path where the data should be stored</param> /// <param name="ramSticks">The list of RamStick objects that need to be exported</param> internal static void ExportHtml(string path, List <RamStick> ramSticks) { if (ramSticks == null || ramSticks.Count == 0) { throw new ArgumentNullException(); } StringBuilder sb = new StringBuilder(); sb.Append("<html><head><title>MemPlus - Ram Analyzer Data</title></head><body><h1>MemPlus - Ram Analyzer Data (" + DateTime.Now + ")</h1>"); for (int index = 0; index < ramSticks.Count; index++) { RamStick stick = ramSticks[index]; sb.Append("<table border=\"1\"><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>"); foreach (RamData data in stick.GetRamData()) { sb.Append("<tr><td>" + data.Key + "</td><td>" + data.Value + "</td></tr>"); } sb.Append("</tbody></table>"); if (index == ramSticks.Count - 1) { continue; } sb.Append("<br />"); } sb.Append("</body></html>"); Export(path, sb.ToString()); }
/// <summary> /// Export a list of RamStick objects to a specific path in text format /// </summary> /// <param name="path">The path where the data should be stored</param> /// <param name="ramSticks">The list of RamStick objects that need to be exported</param> internal static void ExportText(string path, List <RamStick> ramSticks) { if (ramSticks == null || ramSticks.Count == 0) { throw new ArgumentNullException(); } StringBuilder sb = new StringBuilder(); sb.Append("MemPlus - Ram Analyzer Data (" + DateTime.Now + ")"); sb.Append(Environment.NewLine + "---" + Environment.NewLine); for (int index = 0; index < ramSticks.Count; index++) { RamStick stick = ramSticks[index]; List <RamData> ramDataList = stick.GetRamData(); for (int i = 0; i < ramDataList.Count; i++) { sb.Append(ramDataList[i].Key + "\t" + ramDataList[i].Value); if (i == ramDataList.Count - 1) { continue; } sb.Append(Environment.NewLine); } if (index == ramSticks.Count - 1) { continue; } sb.Append(Environment.NewLine + "----------" + Environment.NewLine); } Export(path, sb.ToString()); }
public static ICollection <RamStick> GetRamSticks() { List <RamStick> list = new List <RamStick>(); string[] properties = new string[5] { "Capacity", "ConfiguredClockSpeed", "Manufacturer", "SerialNumber", "PositionInRow" }; WmiInstanceClassCollection wmiInstanceClassCollection = WmiInstance.Query("Win32_PhysicalMemory", properties); if (wmiInstanceClassCollection == null) { return(list); } foreach (WmiInstanceClass item2 in wmiInstanceClassCollection) { RamStick item = new RamStick((ulong?)item2["Capacity"].Value, (uint?)item2["ConfiguredClockSpeed"].Value, (string)item2["Manufacturer"].Value, (string)item2["SerialNumber"].Value, (uint?)item2["PositionInRow"].Value); list.Add(item); } return(list); }
// Token: 0x06000052 RID: 82 RVA: 0x000028D0 File Offset: 0x00000AD0 public static ICollection <RamStick> GetRamSticks() { List <RamStick> list = new List <RamStick>(); string[] properties = new string[] { "Capacity", "ConfiguredClockSpeed", "Manufacturer", "SerialNumber", "PositionInRow" }; WmiClassCollection wmiClassCollection = Wmi.Query("Win32_PhysicalMemory", properties, null); bool flag = wmiClassCollection == null; ICollection <RamStick> result; if (flag) { result = list; } else { foreach (WmiClass wmiClass in wmiClassCollection) { RamStick item = new RamStick((ulong?)wmiClass["Capacity"].Value, (uint?)wmiClass["ConfiguredClockSpeed"].Value, (string)wmiClass["Manufacturer"].Value, (string)wmiClass["SerialNumber"].Value, (uint?)wmiClass["PositionInRow"].Value); list.Add(item); } result = list; } return(result); }
public static ICollection <RamStick> GetRamSticks() { List <RamStick> ramSticks = new List <RamStick>(); string[] requiredProperties = new string[] { "Capacity", "ConfiguredClockSpeed", "Manufacturer", "SerialNumber", "PositionInRow" }; WmiClassCollection classCollection = Wmi.Query(Wmi.PHYSICALMEMORY_CLASSNAME, requiredProperties); if (classCollection == null) { return(ramSticks); } foreach (WmiClass wmiClass in classCollection) { RamStick ramStick = new RamStick( (ulong?)wmiClass["Capacity"].Value, (uint?)wmiClass["ConfiguredClockSpeed"].Value, (string)wmiClass["Manufacturer"].Value, (string)wmiClass["SerialNumber"].Value, (uint?)wmiClass["PositionInRow"].Value); ramSticks.Add(ramStick); } return(ramSticks); }