473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

check RAM size and configuration?

Hi coders,

How can check the total RAM size and the number of RAM modules and their
respective sizes using C#?

Regards,
Tarun
Oct 9 '06 #1
6 18247

"Tarun" <Ta***@discussions.microsoft.comwrote in message
news:3B**********************************@microsof t.com...
| 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.

Oct 9 '06 #2
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:
>
"Tarun" <Ta***@discussions.microsoft.comwrote in message
news:3B**********************************@microsof t.com...
| 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.

Oct 9 '06 #3
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.

"Tarun" <Ta***@discussions.microsoft.comwrote in message
news:2F**********************************@microsof t.com...
| 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:
|
| >
| "Tarun" <Ta***@discussions.microsoft.comwrote in message
| news:3B**********************************@microsof t.com...
| | 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.
| >
| >
| >
| >
Oct 9 '06 #4
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 [MVP]" wrote:
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.

"Tarun" <Ta***@discussions.microsoft.comwrote in message
news:2F**********************************@microsof t.com...
| 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:
|
| >
| "Tarun" <Ta***@discussions.microsoft.comwrote in message
| news:3B**********************************@microsof t.com...
| | 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.
| >
| >
| >
| >
Oct 10 '06 #5
Hi Tarun,

Not sure why your approach does not return any values, nor does it return
anything on my system.
However, there is another somewhat more complicated way which I suspect
Willy was thinking of, where you query the system tables

The code is like this

static void Main(string[] args)
{
ManagementScope scope = new ManagementScope();
ObjectQuery query = new ObjectQuery("SELECT * FROM
Win32_PhysicalMemory");

ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
ManagementObjectCollection coll = searcher.Get();

foreach (ManagementObject mo in coll)
{
Console.WriteLine("Capacity = "
+ mo.Properties["Capacity"].Value);
}
}
On Tue, 10 Oct 2006 06:01:01 +0200, Tarun
<Ta***@discussions.microsoft.comwrote:
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 [MVP]" wrote:
>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.

"Tarun" <Ta***@discussions.microsoft.comwrote in message
news:2F**********************************@microso ft.com...
| 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:
|
| >
| "Tarun" <Ta***@discussions.microsoft.comwrote in message
| news:3B**********************************@microsof t.com...
| | 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.
| >
| >
| >
| >


--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 10 '06 #6
You have to query the "instances" of these classes and enumerate their
properties, what you do is creating a class, but classes don't hold any
instance values, just take a look at Morten's post for a sample.
It's fundamental you understand the difference between a class and an
instance of a class, therefore I would suggest you to take a look at the WMI
doc's before you waste any more time with this. An excellent tool to help
you understand WMI is wbemtest.exe, give it a try.
Willy.

"Tarun" <Ta***@discussions.microsoft.comwrote in message
news:00**********************************@microsof t.com...
| 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 [MVP]" wrote:
|
| 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.
| >
| "Tarun" <Ta***@discussions.microsoft.comwrote in message
| news:2F**********************************@microsof t.com...
| | 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:
| |
| | >
| | "Tarun" <Ta***@discussions.microsoft.comwrote in message
| | news:3B**********************************@microsof t.com...
| | | 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.
| | >
| | >
| | >
| | >
| >
| >
| >
Oct 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: xixi | last post by:
hi, we are using db2 udb v8.1 on windows, i try to use the configuration advisor to get recommendation on the parameter setting, at first, i give the target memory for DB2 is 80% of the physical...
10
by: xixi | last post by:
hi, we are using db2 udb v8.1 on windows, normally i would use control center to change bufferpool size since i know the change will be effect immediately for version 8.1, so i right click...
1
by: Mike Sharp | last post by:
Hi all, I have a few questions. 1. Is there a practical maximum size for a web.config file? Point of diminishing returns? My reason for asking is that I am storing a fairly large amount of...
4
by: Nikolay Petrov | last post by:
I have an class library, which I shared with some of my apps. Some of them are Winfroms apps, others are ASP .NET. How could I check from a method in my library, is it called form an Winforms or...
4
by: vigori | last post by:
I have an application that send a file to a web service (I built both the application and the web service) I set the max file size via web.config of the web service: <httpRuntime...
5
by: Steve | last post by:
WSE352 Size of the record exceed its limit I have a C#.Net windows app that calls a FileNet web service. I can run a select against the web service and it returns up to 7,200 records with 5...
2
by: Dominique | last post by:
Hello, Im want to fix the width of a dashboard. I have a field which has a field (in this dashboard on the left part of my screen) which could be long and make the right side of the screen out...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
3
by: g.deogirikar | last post by:
Hi, What size is set for the bufferpool when "alter bufferpool....size -1 " is issued. Deogirikar.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.