Get the system’s board serial numbers and CPU IDs in C#

[example]

This example shows how to get the system’s board serial numbers and CPU IDs. WMI (Windows Management Instrumentation) lets you use SQL-like statements to ask the computer about itself.

The GetBoardSerialNumbers function shown in the following code returns a list containing the mother board serial numbers.

// Use WMI to return the system's base board serial numbers.
private List GetBoardSerialNumbers()
{
    List results = new List();

    string query = "SELECT * FROM Win32_BaseBoard";
    ManagementObjectSearcher searcher =
        new ManagementObjectSearcher(query);
    foreach (ManagementObject info in searcher.Get())
    {
        results.Add(
            info.GetPropertyValue("SerialNumber").ToString());
    }

    return results;
}

The code uses the WMI query SELECT * FROM Win32_BaseBoard to get information about the system’s mother boards (base boards). The code loops through the resulting collection of Win32_BaseBoard ManagementObjects and adds their SerialNumber values to the result list.

The GetCpuIds function shown in the following code returns a list containing the system’s CPU IDs.

// Use WMI to return the CPUs' IDs.
private List GetCpuIds()
{
    List results = new List();

    string query = "Select * FROM Win32_Processor";
    ManagementObjectSearcher searcher =
        new ManagementObjectSearcher(query);
    foreach (ManagementObject info in searcher.Get())
    {
        results.Add(
            info.GetPropertyValue("ProcessorId").ToString());
    }

    return results;
}

This method uses the WMI query SELECT * FROM Win32_Processor to get information about the system’s processors. The code loops through the resulting collection of Win32_Processor ManagementObjects and adds their ProcessorId values to the result list.

The following code shows how the main program displays the results in ListBoxes.

// Display the mother board serial numbers and the CPU IDs.
private void Form1_Load(object sender, EventArgs e)
{
    lstBoardSerialNumbers.DataSource = GetBoardSerialNumbers();
    lstCpuIds.DataSource = GetCpuIds();
}

This code simply calls the two methods to get the board serial numbers and the CPU IDs. It then sets the ListBox controls’ DataSource properties equal to the returned lists of values.


Download Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in system, WMI and tagged , , , , , , , , , , , , . Bookmark the permalink.

3 Responses to Get the system’s board serial numbers and CPU IDs in C#

  1. javad says:

    thx for source
    but i want to save boardID in a string value not in listbox
    i dont want to show BoardID to anyone in program
    just want to save in a string value

  2. javad says:

    i found out
    now i want to register this program just for this system by board id that anyone else cant use this program except buy another program
    how can i do that?

Leave a Reply

Your email address will not be published. Required fields are marked *