473,409 Members | 1,983 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,409 software developers and data experts.

in C# how do i get to total number of kilobytes of memroy total and available for the current machine?

in C# how do i get to total number of kilobytes of memroy total and
available for the current machine?
Nov 17 '05 #1
3 4420
> in C# how do i get to total number of kilobytes of memroy total and
available for the current machine?

This seems to work:

ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM
Win32_OperatingSystem");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);

ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("Available memory: {0}",
m["FreePhysicalMemory"]);
}

query = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
searcher = new ManagementObjectSearcher(scope, query);
queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("Total memory: {0}",
m["TotalPhysicalMemory"]);
}

Greetings,
Wessel
Nov 17 '05 #2
Another approach will be usage of performance counters..

--

SevDer
http://www.sevder.com
A new .NET Source For .NET Developers
"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.sunwzda5f3yrl7@asbel...
in C# how do i get to total number of kilobytes of memroy total and
available for the current machine?

This seems to work:

ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM
Win32_OperatingSystem");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);

ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("Available memory: {0}",
m["FreePhysicalMemory"]);
}

query = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
searcher = new ManagementObjectSearcher(scope, query);
queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("Total memory: {0}",
m["TotalPhysicalMemory"]);
}

Greetings,
Wessel

Nov 17 '05 #3

"SevDer" <se****@newsgroup.nospam> wrote in message
news:un*************@TK2MSFTNGP14.phx.gbl...
Another approach will be usage of performance counters..

--


It's not possible to get the total system memory (RAM) from perfcounters,
available memory is no problem though.

Willy.
Nov 17 '05 #4

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

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
4
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can...
1
by: beavenour | last post by:
I am looking for some help creating a more universal function out of this lame attempt at javascript. I have little experience with javascript and want to be able to universalize this function. ...
2
by: msnews | last post by:
Hi All, We have a requirement to display total number of current users using the site. We want to display only the total no other information. And this value needs to change dynamically. Is it...
1
by: Daniel | last post by:
in C# how do i get to total number of kilobytes of memroy total and available for the current machine?
2
by: Ryan | last post by:
Access97 I hope someone out there can help. This is driving me crazy. Basically, I am trying to recreate VBA's built in navigation feature (The one that allows you to move first, next,...
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
5
by: junky_fellow | last post by:
Hi guys, I have some value stored in an unsigned long integer. My requirement is to zero the 13 LSB bits of this number. Or more specifically, I want to make the number 8k (8192) aligned. For...
4
by: pbd22 | last post by:
Hi. Could somebody provide me with a formula (or, better, a code example) for converting kilobytes to hours (or, time) from the server? Thanks.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.