SysInfo etc

  • Thread starter Thread starter Mark Rae
  • Start date Start date
M

Mark Rae

Hi,

Is there a native .NET way of interrogating SysInfo details e.g. amount of
physical RAM, OS version etc, or does it still involve Win32 API?

Any assistance gratefully received.

Best regards,

Mark Rae
 
Check the System.Management classes, they wrap WMI, which contains a bunch
of classes that can be used to get such info and much more.

Start with this sample using WMI class Win32_Computersystem.

using System;
using System.Management;
// Dump all properties of CIMV2\Win32_ComputerSystem

class App {
public static void Main() {
ManagementObject cs;
using(cs = new ManagementObject ("Win32_ComputerSystem.Name='"+
System.Environment.MachineName +"'" ))
{
cs.Get();
PropertyDataCollection csProperties = cs.Properties;
foreach (PropertyData csProperty in csProperties ) {
if(csProperty.Value !=null) // Show only non-null property values
Console.WriteLine("Property = {0}\t Value = {1}",
csProperty.Name, csProperty.Value);
}
}
}
Willy.
 
Check the System.Management classes, they wrap WMI, which contains a bunch
of classes that can be used to get such info and much more.

Thanks very much - that helped a lot! From your initial assistance, I came
up with the following, which does the job:

using System.Management;

ObjectQuery objObjectQuery = new ObjectQuery("SELECT * FROM
Win32_PhysicalMemory");
ManagementObjectSearcher objSearcher = new
ManagementObjectSearcher(objObjectQuery);
long lngPhysicalMemory = 0;
foreach (ManagementObject objMemoryObject in objSearcher.Get())
{
lngPhysicalMemory += Convert.ToInt64(objMemoryObject["Capacity"]);
}
lblPhysicalMemory.Text += (lngPhysicalMemory / 1024).ToString("##,###0") + "
KB";
 
Back
Top