How do you get total amount of RAM the computer has?

Joel picture Joel · Sep 19, 2008 · Viewed 137.2k times · Source

Using C#, I want to get the total amount of RAM that my computer has. With the PerformanceCounter I can get the amount of Available ram, by setting:

counter.CategoryName = "Memory";
counter.Countername = "Available MBytes";

But I can't seem to find a way to get the total amount of memory. How would I go about doing this?

Update:

MagicKat: I saw that when I was searching, but it doesn't work - "Are you missing an assembly or reference?". I've looked to add that to the References, but I don't see it there.

Answer

MagicKat picture MagicKat · Sep 19, 2008

Add a reference to Microsoft.VisualBasic and a using Microsoft.VisualBasic.Devices;.

The ComputerInfo class has all the information that you need.