Quick and easy way to get cpu, screen resolution, and RAM information in a windows form application.

Quick and easy way to get cpu, screen resolution, and RAM information in a windows form application.

First, add the follwoing namespaces

using Microsoft.Win32;

using System.Management;

 

once you add those,  you are good to go:

        string cpu = string.Empty;
         string screenResolution = string.Empty;
         string ramSizeInGigaBytes = string.Empty;
         string ramSizeInKiloBytes = string.Empty;

         //get the screen resolution
         screenResolution = string.Format("{0} by {1}", SystemInformation.PrimaryMonitorSize.Width.ToString(), SystemInformation.PrimaryMonitorSize.Height.ToString());

         //get CPU info
         RegistryKey RegKey = Registry.LocalMachine;
         RegKey = RegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
         Object cpuSpeed = RegKey.GetValue("~MHz");
         Object cpuType = RegKey.GetValue("VendorIdentifier");
         cpu = string.Format("{0} - {1} MHz.", cpuType, cpuSpeed);

         //get RAM
         ManagementObjectSearcher Search = new ManagementObjectSearcher("Select * From Win32_ComputerSystem");
         foreach (ManagementObject Mobject in Search.Get())
         { double Ram_Bytes = (Convert.ToDouble(Mobject["TotalPhysicalMemory"]));
            ramSizeInKiloBytes =  (Ram_Bytes / 1024).ToString();
            ramSizeInGigaBytes = (Ram_Bytes / 1073741824).ToString();
         }

         MessageBox.Show("cpu: " + cpu);
         MessageBox.Show("screen res: " + screenResolution);
         MessageBox.Show("ram KB: " + ramSizeInKiloBytes);
         MessageBox.Show("ram GB: " + ramSizeInGigaBytes);

 

 

4 Comments

Comments have been disabled for this content.