In Focus

Get the Processor Details of Your System in Windows Form

This article describes how to get the Processor details of your System. Here I will get the information from the Win32_Processor class.

Introduction

This article explains how to get the details of the processor
of your system. Here I will get the information from the Win32_Processor class.

What Win32_Processor is

The Win32_Processor WMI Class represents a device that can interpret a sequence of instructions on a computer running on a Windows operating system.


Design

Create a new Windows Forms Application Project.

Add one button control to the form.

Design your screen as in the following screen:

Next add a reference for "System.Management".


To add the reference use the following procedure.

Go to Solution Explorer, select the project and right-click on that and choose "Add Reference" from the menu.


A window will open; in that choose the ".Net" tab.

3.jpg

It will show a list. In that list, choose "System.Management" and click the "OK" Button.

4.jpg

 Now go to code view.

Add the namespace "using System.Management;".

Write the following code for the Button Click event
:

private
void button1_Click(object sender, EventArgs e)
       
{

           
SelectQuery Sq = new SelectQuery("Win32_Processor");

           
ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);

           
ManagementObjectCollection osDetailsCollection = objOSDetails.Get();

           
StringBuilder sb = new StringBuilder();

           
foreach (ManagementObject mo in osDetailsCollection)

           
{

               
sb.AppendLine(string.Format("Name : {0}", (string)mo["Name"]));

 
              sb.AppendLine(string.Format("Availability: {0}", (ushort)mo["Availability"]));

               
sb.AppendLine(string.Format("Architecture: {0}", (ushort)mo["Architecture"]));

               
sb.AppendLine(string.Format("AddressWidth: {0}", (ushort)mo["AddressWidth"]));

               
sb.AppendLine(string.Format("Caption: {0}", (string)mo["Caption"]));

               
sb.AppendLine(string.Format("InstallDate: {0}", Convert.ToDateTime(mo["InstallDate"]).ToString()));

               
sb.AppendLine(string.Format("ConfigManagerUserConfig: {0}", (string)mo["ConfigManagerUserConfig"]));

               
sb.AppendLine(string.Format("CpuStatus : {0}", (ushort)mo["CpuStatus"]));

               
sb.AppendLine(string.Format("CreationClassName : {0}", (string)mo["CreationClassName"]));

               
sb.AppendLine(string.Format("CurrentClockSpeed : {0}", mo["CurrentClockSpeed"]).ToString());

               
sb.AppendLine(string.Format("CurrentVoltage : {0}", (ushort)mo["CurrentVoltage"]));

               
sb.AppendLine(string.Format("DataWidth : {0}", (ushort)mo["DataWidth"]));

               
sb.AppendLine(string.Format("Description: {0}", (string)mo["Description"]));

               
sb.AppendLine(string.Format("DeviceID : {0}", (string)mo["DeviceID"]));

               
sb.AppendLine(string.Format("ErrorCleared: {0}", (string)mo["ErrorCleared"]));

               
sb.AppendLine(string.Format("ErrorDescription : {0}", (string)mo["ErrorDescription"]));

               
sb.AppendLine(string.Format("ExtClock : {0}", mo["ExtClock"]).ToString());

               
sb.AppendLine(string.Format("Family : {0}", (ushort)mo["Family"]));

               
sb.AppendLine(string.Format("L2CacheSize : {0}", mo["L2CacheSize"]).ToString());

             
  sb.AppendLine(string.Format("L2CacheSpeed : {0}", mo["L2CacheSpeed"]).ToString());

               
sb.AppendLine(string.Format("L3CacheSize : {0}", mo["L3CacheSize"]).ToString());

               
sb.AppendLine(string.Format("L3CacheSpeed : {0}", mo["L3CacheSpeed"]).ToString());

               
sb.AppendLine(string.Format("LastErrorCode : {0}", mo["LastErrorCode"]).ToString());

               
sb.AppendLine(string.Format("Level : {0}", (ushort)mo["Level"]));

               
sb.AppendLine(string.Format("LoadPercentage: {0}", (ushort)mo["LoadPercentage"]));

               
sb.AppendLine(string.Format("Manufacturer: {0}", (string)mo["Manufacturer"]));

               
sb.AppendLine(string.Format("MaxClockSpeed : {0}", mo["MaxClockSpeed"]).ToString());

               
sb.AppendLine(string.Format("NumberOfCores : {0}", mo["NumberOfCores"]).ToString());

               
sb.AppendLine(string.Format("OtherFamilyDescription: {0}", (string)mo["OtherFamilyDescription"]));

               
sb.AppendLine(string.Format("NumberOfLogicalProcessors : {0}", mo["NumberOfLogicalProcessors"]).ToString());

               
sb.AppendLine(string.Format("PNPDeviceID: {0}", (string)mo["PNPDeviceID"]));

               
sb.AppendLine(string.Format("PowerManagementSupported : {0}", mo["PowerManagementSupported"].ToString()));

               
sb.AppendLine(string.Format("ProcessorId: {0}", (string)mo["ProcessorId"]));

               
sb.AppendLine(string.Format("ProcessorType : {0}", (ushort)mo["ProcessorType"]));

               
sb.AppendLine(string.Format("Revision: {0}", (ushort)mo["Revision"]));

               
sb.AppendLine(string.Format("Role: {0}", (string)mo["Role"]));

               
sb.AppendLine(string.Format("SocketDesignation : {0}", mo["SocketDesignation"]).ToString());

 
               sb.AppendLine(string.Format("Status : {0}", (string)mo["Status"]));

               
sb.AppendLine(string.Format("StatusInfo: {0}", (ushort)mo["StatusInfo"]));

               
sb.AppendLine(string.Format("Stepping : {0}", (string)mo["Stepping"]));

               
sb.AppendLine(string.Format("SystemCreationClassName : {0}", (string)mo["SystemCreationClassName"]));

               
sb.AppendLine(string.Format("SystemName: {0}", (string)mo["SystemName"]));

               
sb.AppendLine(string.Format("UniqueId : {0}", (string)mo["UniqueId"]));

               
sb.AppendLine(string.Format("UpgradeMethod: {0}", (ushort)mo["UpgradeMethod"]));

               
sb.AppendLine(string.Format("Version: {0}", (string)mo["Version"]));

               
sb.AppendLine(string.Format("VoltageCaps : {0}", mo["VoltageCaps"]).ToString());

           
}

           
MessageBox.Show(sb.ToString());

       
}

 

In the code above I am getting the information from Win32_Processor and showing it in a Message Box on a button click.

SelectQuery

It represents a WMI Query Language (WQL) SELECT data query.

ManagementObjectSearcher

It retrieves a collection of management objects based on a specified query.

This class is one of the more commonly used entry points for retrieving management information.

ManagementObjectCollection

It represents various collections of management objects retrieved using WMI.

Now build your application. Click on the button; it will show the processor details in a Message box.


 

Thank you.