views:

61

answers:

1

hi all i have this great code that i love that will display the kind of processor model and speed like so

RegistryKey Rkey = Registry.LocalMachine;
Rkey = Rkey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
Labelproc.Text = (string)Rkey.GetValue("ProcessorNameString");

and i was wondering if theres a way to do this for the kind of graphics card and the total installed system ram (in separate labels)

A: 

Rather than reading the registry I'd suggest that you use WMI, specifically Win32_ComputerSystem to find number of CPUs and Win32_Processor to find info about it and Win32_ComputerSystem.TotalPhysicalMemory would give the RAM.
I'm sure there is some way to pick up the graphics card(s) as well (remember that there might be more than one).

Here's an article with some samples for getting out various data:

http://msdn.microsoft.com/en-us/library/aa394587%28VS.85%29.aspx

The samples are in vbscript but it's similar, I think the C# code for getting the RAM would be something like:

ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") ;
ManagementObjectCollection coll = query.Get();
foreach( ManagementObject mo in coll ) 
{
    Console.WriteLine(mo["totalphysicalmemory"].ToString());
}    
ho1
seems to work good but it says "4222832640" and i have 4gb of installed RAM how can i have it so it just says 4GB or say 256MB if that were the case?
NightsEVil
@NightsEVil: I assume it's just divide by 1073741824 for GB or 1048576 for MB. You might have to round it up to the nearest suitable value (it's saying that you have 3.93 GB of RAM, I'm not sure why that is).
ho1
but is there any way to have it automatically do the calculation and display the result as 4GB or 256MB?
NightsEVil
Don't know I'm afraid. I'm guessing not though, since it's not too difficult to fix the result yourself. Might be some other way of getting hold of that data that would present it in a nicer way.
ho1
isnt there any way i can put something in where if 4222832640 = 4gb ect?
NightsEVil