Hi Willy,
Thanks a lot. You really guided me in the right direction. I wrote the
following but I still don't get any output.
using System;
using System.Management;
namespace MemoryTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Test
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Test t1 = new Test();
t1.checkRAM();
Console.Read();
}
void checkRAM ()
{
ManagementClass myRAM = new ManagementClass("Win32_PhysicalMemory");
myRAM.Get();
Console.Write(myRAM.GetPropertyValue("Capacity"));
}
}
}
Regards,
Tarun
Willy Denoyette said:
Where did you read Win32_PhysicalMemoryArray? You need to query the
instances of Win32_PhysicalMemory and add the Capacity property value
to get
the total RAM. If you need to obtain the memory bank occupation, you'll
have
to retrieve the Win32_MemoryDevice instances and fetch the beginaddress
and
eningaddress properties of each instance, if the endingaddress is 0, the
bank is free, else it's occupied.
Willy.
| Thanks for your reply. I tried using the following code, querying the
Win32
| class from C# code:-
|
| ManagementClass myRAM = new
ManagementClass("Win32_PhysicalMemoryArray");
| myRAM.Get();
| Console.WriteLine("Total Physical Memory: " +
| myRAM.GetPropertyValue("MaxCapacity"));
|
| However, this does not show the memory size. In fact, it does not
give any
| output. But another query - myRAM.Properties.Count works absolutely
fine,
| returning 27.
|
| Kindly help me with this.
|
| Regards,
| Tarun
|
| "Willy Denoyette [MVP]" wrote:
|
| >
| > | > | Hi coders,
| > |
| > | How can check the total RAM size and the number of RAM modules and
their
| > | respective sizes using C#?
| > |
| > | Regards,
| > | Tarun
| >
| > Query the WMI classes Win32_PhyscalMemory and Win32_MemoryDevice
using
| > System.Management namespace classes.
| >
| > Willy.
| >
| >
| >
| >