The following code shows you how to retrieve it using a foreach loop. Note that this property retrieves the memory in bytes and I've did some calculations to display it in GB. Then, this method can be used to display the memory amount inside a label... or whatever.
private static String getRAMsize() { ManagementClass mc = new ManagementClass("Win32_ComputerSystem"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject item in moc) { return Convert.ToString(Math.Round(Convert.ToDouble(item.Properties["TotalPhysicalMemory"].Value) / 1073741824, 2)) + " GB"; } return "RAMsize"; }
does it work for 64 bit???
ReplyDelete