-4

hi edit this code but get error " Cannt apply indexing with [] to an expression of type "view_process.managmentobject" for line 8

and what is formul for get 30% my memory?

private static void DisplayTotalRam()
    {
        string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray";
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(Query);
        int amount = 0;
        foreach (ManagementObject memo in searcher.Get())
        {
            amount += Convert.ToInt32(Convert.ToInt64(memo["Capacity"]) / 1024 / 1024 / 1024);

        }
    }
user2223755
  • 9
  • 1
  • 1
  • 2
  • Possible duplicate of : http://stackoverflow.com/questions/105031/how-do-you-get-total-amount-of-ram-the-computer-has – Sasha Apr 03 '13 at 14:54

1 Answers1

2

Add a reference to Microsoft.VisualBasic.dll. Then getting total physical memory is as simple as this (yes, I tested it):

static ulong GetTotalMemoryInBytes()
{
    return new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory;
}
Ahmed KRAIEM
  • 10,267
  • 4
  • 30
  • 33