Retrieving Motherboard Serial Number Via WMI

Introduction

A simple way to get system information is through Windows Management Instrumentation (WMI).

WMI was first introduced as part of Windows 2000. It's designed to help your system, applications, and networks.

WMI has an amazing design; It's implemented like a large database that contains several tables and types. And you can query it using SQL statements (really!).

Classes .NET Framework with WMI

These classes reside in the assembly System. Management that you can reference in your project.

Querying WMI is very simple. First, create a ManagementObjectSearcher object that will hold the SQL query. Then you execute the query by calling the Get() method of the ManagementObjectSearcher object, which returns a collection of ManagementObject objects. This object looks like rows in a database that you can access its columns -PropertyData objects- and retrieve their values.

In WMI, tables are called classes, rows are called objects, and columns are called properties.

The following example demonstrates how to get Motherboard information, like its name and serial number.

using System;
using System.Management;
class Program
{
    static void Main()
    {
        using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Product, SerialNumber FROM Win32_BaseBoard"))
        {
            // Executing the query...
            // Because the machine has a single Motherboard, then a single object (row) returned.
            ManagementObjectCollection information = searcher.Get();
            foreach (ManagementObject obj in information)
            {
                // Retrieving the properties (columns)
                // Writing column name then its value
                foreach (PropertyData data in obj.Properties)
                {
                    Console.WriteLine("{0} = {1}", data.Name, data.Value);
                }
                Console.WriteLine();
            }
        }
    }
}

To read more about WMI and get lists of classes and features that it supports, see WMI Reference. A long time ago, I used that mechanism to protect my application from copying it from one PC to another. The application asks the user for the serial number if he changed his PC (frankly, Motherboard). Did you validate? The serial number itself is an encrypted hash of the Motherboard serial number.


Similar Articles