---
title: "Problem in getting the physical memory of system"  
description: "Problem in getting the physical memory of system"  
author: "Rajesh Goswami"  
published: 2011-10-21  
updated: 2011-10-21  
canonical: https://www.mindstick.com/forum/332/problem-in-getting-the-physical-memory-of-system  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Problem in getting the physical memory of system

Hi,\
There is some [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) related to get the information about the [system](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) and total [physical](https://yourviews.mindstick.com/view/82619/leave-digital-live-physical) [memory](https://www.mindstick.com/blog/300050/what-causes-sudden-memory-loss) in system\
\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by Rajesh Goswami

Thanks Rohit,\
\
Now I got real solution again thanks.

### Reply by Chris Anderson

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");
```

### Reply by Chris Anderson

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());            }
```


---

Original Source: https://www.mindstick.com/forum/332/problem-in-getting-the-physical-memory-of-system

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
