Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding system information in code

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Good day all.
I was using a Performance counter to get the amount of RAM still available. This got me thinking, "Well, how much did I have to start with?"

Does anyone have a suggestion or a link to a sample for finding System information in code (I'm using Visual Studio 2005).

ie: Amount of RAM, processor speed, drive sizes, etc.

Thanks everyone.
Patrick
 
have you tried googling for the answer? i would start with the System.Enviornment object and go from there. google can also be a great resource.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Yes, I tried to google it. Mostly there were just obscure articles about system information, but no code. Now when I run this search in google.

+"c sharp" +"System Information"

THIS POST ranks #1 on GOOGLE'S SEARCH ENGINE, and (so far) there is no information about it here.

Would someone who cares about the quality of content on the forum help us all out by sharing what they know about this topic and having the #1 ranked search for this keyword combination actually contain information about the topic?

Thanks everyone.
Patrick
 
Well, when I simply searched for 'C# system information' (without the 's) I got this as the first hit:


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello again everyone.

Here is what I found.
System.Environment will get you Operating System Info.

From the link, System.Windows.Forms.SystemInformation will
get you Monitor Info and Window info.

To get good RAM stats use this.

public struct MEMORYSTATUSEX
{
public int dwLength;
public int dwMemoryLoad;
public ulong ullTotalPhys;
public ulong ullAvailPhys;
public ulong ullTotalPageFile;
public ulong ullAvailPageFile;
public ulong ullTotalVirtual;
public ulong ullAvailVirtual;
public ulong ullAvailExtendedVirtual;
}

[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
//I just threw this method together to step through and watch the variables
Private Void myMethod()
{
MEMORYSTATUSEX memStat= new MEMORYSTATUSEX();
memStat.dwLength = 64;
bool b = GlobalMemoryStatusEx( ref memStat );
int y = memStat.dwLength;
ulong x;
y = memStat.dwMemoryLoad;
x = memStat.ullAvailExtendedVirtual;
x = memStat.ullAvailPageFile;
x = memStat.ullAvailPhys;
x = memStat.ullAvailVirtual;
x = memStat.ullTotalPageFile;
x = memStat.ullTotalPhys;
x = memStat.ullTotalVirtual;
}
 
Isn't all that information in WMI as well?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top