• Favorite
  • Facebook
  • Twitter
  • LinkedIn

Microsoft Press Pearson Education (InformIT)
Skip Navigation Links
Pearson Education (InformIT)
How to: Get your Machine Processor Id using C#

Sometimes you need to store a piece of information that uniquely identifies the machine your application runs on. One of the information that uniquely identifies the machine is the Processor Id. In this article we will create an application that retrieves the machine Processor Id.


In this article we use the Windows Management Instrumentation. For more information about Windows Management Instrumentation see the following MSDN section


Using the Code:

To create an application that retrieves the machine Processor Id follow the following steps:

1.      Create a new windows application using Visual Studio 2005/2008/2010.

2.      Rename Form1 to ProcessorForm.

3.      Add a ToolStrip control to the ProcessorForm and rename it to ProcessorToolStrip.

4.      Add a ToolStripButton to the ProcessorToolStrip and rename it to ProcessorToolStripButton and set its Text property to Processor.

5.      Right click the References under your project and select Add Reference. Select .NET Tab and find the System.Management namespace and click OK.




6.      Import the System.Management namespace  using the following statement:

using System.Management;

7.      The System.Management namespace provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. Applications and services can query for interesting management information, using classes derived from ManagementObjectSearcher and ManagementQuery, or subscribe to a variety of management events using the ManagementEventWatcher class. The accessible data can be from both managed and unmanaged components in the distributed environment.

8.      Double click the ProcessorToolStripButton to create the Click Event Handler.

9.      Add the following code to the ProcessorToolStripButton Click Event Handler:

private void ProcessorToolStripButton_Click(object sender, EventArgs e)




        StringBuilder processorsBuilder = new StringBuilder();

        ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Processor");


        foreach (ManagementObject managementObject in searcher.Get())


            foreach (PropertyData property in managementObject.Properties)


               if (property.Value == null)




               if (property.Name.ToLower() == "ProcessorId".ToLower())





        MessageBox.Show(processorsBuilder.ToString(), "Available Processors",

            MessageBoxButtons.OK, MessageBoxIcon.Information);


    catch (Exception ex)


        MessageBox.Show(ex.Message, ex.GetType().ToString(),

            MessageBoxButtons.OK, MessageBoxIcon.Error);



Thanks to Adavesh he posted a comment on this article and his code snippet below is more faster than the above code snippet.

private void ProcessorToolStripButton_Click(object sender, EventArgs e)


    string processorId = string.Empty;

    ManagementClass processorManagement = new ManagementClass("Win32_Processor");

    foreach (var processor in processorManagement.GetInstances())




            processorId = processor["ProcessorId"].ToString();

            MessageBox.Show(processorId,"Processor Id",



        catch (Exception ex)


            MessageBox.Show(ex.Message,"An error occured in getting processor Id",







a.      Create an instance of the StringBuilder and name it processorsBuilder. This object will be used to store available processors Ids.

b.     Then we create an instance of the ManagementObjectSearcher class and name it searcher. This class retrieves a collection of management objects based on a specified query. This class is one of the more commonly used entry points to retrieving management information.

c.      We then pass the following WMI Query “Select * From Win32_Processor” to query for every available processors installed on the system.

d.     Then we iterate in the collection of management objects returned from the earlier WMI Query.

e.     When the Get() method on the searcher object is invoked, the ManagementObjectSearcher executes the given query in the specified scope and returns a collection of management objects that match the query in a ManagementObjectCollection.

f.       Then we iterate in the properties of each ManagementObject

g.      If the ManagementObject Property is null we continue to the next property

h.     If the property name of the ManagementObject equals ProcessorId then we append a line to the processorsBuilder with the property value that represents the processor Id.

i.        Then we display the available processor Ids in a MessageBox as follows:

10.  Build and run the application and click the ProcessorToolStripButton this will display available Processors on your machine.

Now you have an application that application that retrieves your machine Processor Id.

(398) Comments

Blog Message rHGCAosRYQSXDekp


Blog Message IkHjCYZNXK


Blog Message nIlrmxsyNROEfoYQ


Blog Message ZVlmOpDtKizL


Blog Message TyqNYdgKGXAnEC


Blog Message kwtLEHVhRnIOxpDB


Blog Message CVJDrIYuNTnom


Blog Message hcnZXxegOuwCs


Blog Message zujMsYQG


Blog Message cJhSCxRoqPQ


Blog Message TwlXeJiMt


Blog Message jKFATMeCxRrcoUHJ


Blog Message yVfaKpJt


Blog Message sxtfYBuNUWRFk


Blog Message IRvfjudqZLaU


First Previous 1 2 3 4 5 6 7 8 9 10  ... Next Last