I have written a fairly basic program in C#, kind of like a system monitor, which our helpdesk uses in order to quickly get some information from users.
It displays Username, Domain, OS, IP and a few other bits of info.
I have since been asked to extend the functionality to include total RAM and the computer serial number, but no matter what i have tried i cant get it to display in to a text box.
What I have tried:
For the RAM i tried using a performance counter, but this only showed available RAM. So i think i need to use WMI?
For the serial i have this:
public static string GetMotherBoardID()
{
string mbInfo = String.Empty;
ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
scope.Connect();
ManagementObject wmiClass = new ManagementObject(scope, new ManagementPath("Win32_BaseBoard.Tag=\"Base Board\""), new ObjectGetOptions());
foreach (PropertyData propData in wmiClass.Properties)
{
if (propData.Name == "SerialNumber")
mbInfo = String.Format("{0,-25}{1}", propData.Name, Convert.ToString(propData.Value));
}
return mbInfo;
ITHelper.txtSerial.Text = mbInfo.ToString();
}
Which displays the following error
An object reference is required for the non-static field, method, or property
For the RAM i have tried
private static void DisplayTotalRam()
{
string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(Query);
int amount = 0;
foreach (ManagementObject memo in searcher.Get())
{
amount += Convert.ToInt32(Convert.ToInt64(memo["Capacity"]) / 1024 / 1024 / 1024);
txtRam.Text = amount.ToString();
}
}
But i get the same message as above