Thursday 7 June 2012

How to get Motherboard serial Number




Hi Friends,


Last week I was working on one window application. In this application we have to get serial number of motherboard.

Following code describes how to get serial number of motherboard.

You need to add a reference to System.Management.dll to your project.


  ManagementScope ms = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
  ms.Connect();
 ManagementObject wmiClass = new ManagementObject(ms, new ManagementPath("Win32_BaseBoard.Tag=\"Base Board\""), new ObjectGetOptions());
string sn = wmiClass.Properties.Cast<PropertyData>().Where(p => p.Name == "SerialNumber").FirstOrDefault().Value.ToString();

  MessageBox.Show(sn);

 

  





In the above code
  • 1.  "\\root\\cimv2: root is because it's the root of the tree. cimv2 is actually CIMv2, because it's version 2 of the CIM (Common Information Model).
  • 2.  ManagementScope() : Initializes a new instance of the Management Scope class, with default values. This is the default constructor.




Happy Programming ! !
If you have any query mail me to Sujeet.bhujbal@gmail.com     

Regards
Sujeet Bhujbal

--------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------