public static ulong GetMemory()
{
try
{
double capacity = 0.0;
var cimobject1 = new ManagementClass("Win32_PhysicalMemory");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (var o in moc1)
{
var mo1 = (ManagementObject)o;
capacity += ((Math.Round(long.Parse(mo1.Properties["Capacity"].Value.ToString()) / 1024 / 1024.0, 1)));
}
moc1.Dispose();
cimobject1.Dispose();
ulong qmem = Convert.ToUInt64(capacity.ToString(CultureInfo.InvariantCulture));
return qmem;
}
catch (System.Runtime.InteropServices.COMException ex)
{
Logger.error("Failed to get the physical memory");
Logger.error(ex);
return ulong.MaxValue;
}
}