Problem in getting the physical memory of system

Total Post:29

Points:203
C# 
C#
 3471  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. 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 Mar-29-2018 04:37:55 AM
  1. 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");

      Modified On Mar-29-2018 04:38:11 AM
  1. 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!