Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / C#

Retrieving Motherboard Serial Number using WMI

Rate me:
Please Sign up or sign in to vote.
4.67/5 (7 votes)
11 May 2010CPL1 min read 50.5K   37   6
Access WMI via C# and retrieve motherboard information

I wrote this article in Arabic too. Check it out here

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

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

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

.NET Framework includes various classes for dealing with WMI. These classes reside on assembly System.Management that you can reference into 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, returns a collection of ManagementObject objects. This object looks like rows in a database that you can access its columns -PropertyData objects- and retrieve its 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:

C#
// First we create the ManagementObjectSearcher that
// will hold the query used.
// The class Win32_BaseBoard (you can say table)
// contains the Motherboard information.
// We are querying about the properties (columns)
// Product and SerialNumber.
// You can replace these properties by
// an asterisk (*) to get all properties (columns).
ManagementObjectSearcher searcher =
    new ManagementObjectSearcher("SELECT Product, SerialNumber FROM Win32_BaseBoard");

// Executing the query...
// Because the machine has a single Motherborad,
// 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();
}

// For typical use of disposable objects
// enclose it in a using statement instead.
searcher.Dispose();

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 a 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!

Posted in WMI Tagged: .NET, CodeProject, CSharp, WMI

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)


Written By
Technical Lead
Egypt Egypt
Mohammad Elsheimy is a developer, trainer, and technical writer currently hired by one of the leading fintech companies in Middle East, as a technical lead.

Mohammad is a MCP, MCTS, MCPD, MCSA, MCSE, and MCT expertized in Microsoft technologies, data management, analytics, Azure and DevOps solutions. He is also a Project Management Professional (PMP) and a Quranic Readings college (Al-Azhar) graduate specialized in Quranic readings, Islamic legislation, and the Arabic language.

Mohammad was born in Egypt. He loves his machine and his code more than anything else!

Currently, Mohammad runs two blogs: "Just Like [a] Magic" (http://JustLikeAMagic.com) and "مع الدوت نت" (http://WithdDotNet.net), both dedicated for programming and Microsoft technologies.

You can reach Mohammad at elsheimy[at]live[dot]com

Comments and Discussions

 
GeneralMy vote of 5 Pin
Аslam Iqbal9-May-13 23:03
professionalАslam Iqbal9-May-13 23:03 
GeneralNice Idea Pin
Moh_ab197926-Mar-10 2:47
Moh_ab197926-Mar-10 2:47 
GeneralRe: Nice Idea Pin
Mohammad Elsheimy26-Mar-10 3:32
Mohammad Elsheimy26-Mar-10 3:32 
GeneralRe: My vote of 1 Pin
Mohammad Elsheimy26-Mar-10 3:31
Mohammad Elsheimy26-Mar-10 3:31 
GeneralRe: My vote of 1 Pin
Mohammad Elsheimy27-Mar-10 4:33
Mohammad Elsheimy27-Mar-10 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.