PROBLEM IN GETTING THE PHYSICAL MEMORY OF SYSTEM

Rajesh Goswami

Total Post:29

Points:203
Posted by  Rajesh Goswami
C# 
C#
 3186  View(s)
Ratings:
Rate this:
Hi,
There is some problem related to get the information about the system and total physical memory in system

Thanks in advance!
  1. Chris Anderson

    Post:65

    Points:455
    Re: Problem in getting the physical memory of system

    Hi,

    You can use the given code to retrieve the system memory in C#:

    using System.Management;

    ManagementObjectSearcher Search = new ManagementObjectSearcher("Select * From Win32_ComputerSystem");
                foreach (ManagementObject Mobject in Search.Get())
                {
                    double Ram_Bytes = (Convert.ToDouble(Mobject["TotalPhysicalMemory"]));
                    MessageBox.Show((Ram_Bytes / (1024 * 1024 * 1024)).ToString());
                }

      Modified On Oct-21-2011 05:05:26 AM
  1. Chris Anderson

    Post:65

    Points:455
    Re: Problem in getting the physical memory of system

    Hi,

    You can also use the following code in order to retrieve physical memory (RAM) :

                double totalCapacity = 0;
                ObjectQuery objectQuery = new ObjectQuery("select * from Win32_PhysicalMemory");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(objectQuery);
                ManagementObjectCollection vals = searcher.Get();

                foreach (ManagementObject val in vals)
                {
                    totalCapacity += System.Convert.ToDouble(val.GetPropertyValue("Capacity"));
                }

                Console.WriteLine("Total Machine Memory = " + totalCapacity.ToString() + " Bytes");
                Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1024) + " KiloBytes");
                Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1048576) + "    MegaBytes");
                Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1073741824) + " GigaBytes");

  1. Rajesh Goswami

    Post:29

    Points:203
    Re: Problem in getting the physical memory of system

    Thanks Rohit,

    Now I got real solution again thanks.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!