ConnectionOptions connection = new ConnectionOptions();
connection.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); foreach (ManagementObject queryObj in searcher.Get())
{
System.Diagnostics.Debug.WriteLine("-----------------------------------");
System.Diagnostics.Debug.WriteLine("Capacity: {0}", queryObj["Capacity"]); System.Diagnostics.Debug.WriteLine("MemoryType: {0}", GetMemoryType(Int32.Parse(queryObj["MemoryType"].ToString())));
}
following is method which differentiate between DDR1,DDR2,DDR3 you can check other types on
WMI Physical Memory Types[
^]
public string GetMemoryType(int MemoryType)
{
switch (MemoryType)
{
case 20:
return "DDR";
break;
case 21:
return "DDR-2";
break;
default:
if (MemoryType == 0 || MemoryType > 22)
return "DDR-3";
else
return "Other";
break;
}