locked
How to get the serial of my motherboard

    Question

  •  

    How to get the serial of my motherboard or hard or cpu

     

    thanks

    Friday, October 5, 2007 8:54 PM

Answers

  • Hi ahmed,

     

    Windows Management Instrumentation (WMI) contains a lot information about your hardware (Such as Motherboard, Hard and Cpu).

     

    You need to Add Reference to System.Management.dll.

    Add Imports system.Management at the top of your source code.

     

    Here is one source-opeded sample.

    How to retrieve REAL Hard Drive Serial Number

    It's one Console project in C#, but I have convert it to VB.NET version as below and it works fine.

    Code Block

    Imports Microsoft.VisualBasic

    Imports System

    Imports System.Collections

    Imports System.Management

     

    Namespace HardDriveSample1

              Friend Class HardDrive

                       Private model_Renamed As String = Nothing

                       Private type_Renamed As String = Nothing

                       Private serialNo_Renamed As String = Nothing

     

                       Public Property Model() As String

                                 Get

                                          Return model_Renamed

                                 End Get

                                 Set(ByVal value As String)

                                          model_Renamed = value

                                 End Set

                       End Property

     

                       Public Property Type() As String

                                 Get

                                          Return type_Renamed

                                 End Get

                                 Set(ByVal value As String)

                                          type_Renamed = value

                                 End Set

                       End Property

     

                       Public Property SerialNo() As String

                                 Get

                                          Return serialNo_Renamed

                                 End Get

                                 Set(ByVal value As String)

                                          serialNo_Renamed = value

                                 End Set

                       End Property

              End Class

     

              Friend Class TestProgram

             

                       <STAThread> _

                       Shared Sub Main(ByVal args As String())

                                 Dim hdCollection As ArrayList = New ArrayList()

     

                                 Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")

     

                                 For Each wmi_HD As ManagementObject In searcher.Get()

                                          Dim hd As HardDrive = New HardDrive()

                                          hd.Model = wmi_HD("Model").ToString()

                                          hd.Type = wmi_HD("InterfaceType").ToString()

     

                                          hdCollection.Add(hd)

                                 Next wmi_HD

     

    searcher = New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")

     

                                 Dim i As Integer = 0

                                 For Each wmi_HD As ManagementObject In searcher.Get()

                                          ' get the hard drive from collection

                                          ' using index

                                          Dim hd As HardDrive = CType(hdCollection(i), HardDrive)

     

                                          ' get the hardware serial no.

                                          If wmi_HD("SerialNumber") Is Nothing Then

                                                    hd.SerialNo = "None"

                                          Else

                                          hd.SerialNo = wmi_HD("SerialNumber").ToString()

                                          End If

     

                                          i += 1

                                 Next wmi_HD

     

                                 ' Display available hard drives

                                 For Each hd As HardDrive In hdCollection

    Console.WriteLine("Model" & Constants.vbTab + Constants.vbTab & ": " & hd.Model)

    Console.WriteLine("Type" & Constants.vbTab + Constants.vbTab & ": " & hd.Type)

    Console.WriteLine("Serial No." & Constants.vbTab & ": " & hd.SerialNo)

    Console.WriteLine()

                                 Next hd

     

                                 ' Pause application

                                 Console.WriteLine("Press [Enter] to exit...")

                                 Console.ReadLine()

                       End Sub

              End Class

    End Namespace

     

     

    If you need the entire source program, please tell me your mailbox, I will send it to you.

     

     

    Regards,

    Martin

    Tuesday, October 9, 2007 9:52 AM
  • Similarly, get the serial number of the motherboard like this:

    Add Reference to System.Management.dll.

    Add Imports system.Management at the top of your source code.

    Code Block

    Imports System.Management

    Module Module1

     

        Sub Main()

     

            Dim oConn As ConnectionOptions = New ConnectionOptions

            oConn.Username = "Administrator"

            oConn.Password = "password"

            Dim oMs As System.Management.ManagementScope = New System.Management.ManagementScope("\\machineID", oConn)

            Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select SerialNumber from Win32_BaseBoard")

            Dim oSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(oMs, oQuery)

            Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get

            For Each oReturn As ManagementObject In oReturnCollection

                Console.WriteLine(("Serial Number : " + oReturn("SerialNumber").ToString))

            Next

            Console.ReadLine()

        End Sub

     

    End Module

    Reference: Win32_MotherboardDevice Class

    Tuesday, October 9, 2007 10:38 AM
  • Similarly, get the CPU ID like this:

    Add Reference to System.Management.dll.

    Add Imports system.Management at the top of your source code.

    Code Block

    Imports System.Management

    Module Module1

     

        Sub Main()

     

            Dim cpuInfo As String = String.Empty

            Dim temp As String = String.Empty

            Dim mc As ManagementClass = New ManagementClass("Win32_Processor")

            Dim moc As ManagementObjectCollection = mc.GetInstances

            For Each mo As ManagementObject In moc

                If (cpuInfo = String.Empty) Then

                    ' only return cpuInfo from first CPU

                    cpuInfo = mo.Properties("ProcessorId").Value.ToString

                    Console.WriteLine(("CPU ID : " & cpuInfo))

                End If

            Next

            Console.ReadLine()

        End Sub

     

    End Module

     

    By the way, here is another good source-opened sample.

    How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...)

     

    Best wishes,

    Martin Xie

    Tuesday, October 9, 2007 10:52 AM
  • Hi ahmed,

     

    Thank you for your feedback.

     

    ProcessorId doesn't mean the Serial Number.

     

    CPUID details:

    http://msdn2.microsoft.com/en-us/library/hskdteyh(vs.80).aspx

    Generates the cpuid instruction available on x86 and x64, which queries the processor for information about the supported features and CPU type.

     

    The supported features and CPU type information is returned in CPUInfo, an array of four 32-bit integers that is filled with the values of the EAX, EBX, ECX, and EDX registers (in that order) after the cpuid instruction is called.

    The information returned has a different meaning depending on the value passed as the InfoType parameter. The information returned with various values of InfoType is processor-dependent.

     

    The following table shows the meaning of the Feature Information value, the value of EDX which is written to CPUInfo[3], when the InfoType argument is 1.

    Feature Information Returned

    Bit

    Mnemonic

    Description

    18

    PSN

    Processor Serial Number

    Monday, January 7, 2008 1:46 PM

All replies

  • Hi ahmed,

     

    Windows Management Instrumentation (WMI) contains a lot information about your hardware (Such as Motherboard, Hard and Cpu).

     

    You need to Add Reference to System.Management.dll.

    Add Imports system.Management at the top of your source code.

     

    Here is one source-opeded sample.

    How to retrieve REAL Hard Drive Serial Number

    It's one Console project in C#, but I have convert it to VB.NET version as below and it works fine.

    Code Block

    Imports Microsoft.VisualBasic

    Imports System

    Imports System.Collections

    Imports System.Management

     

    Namespace HardDriveSample1

              Friend Class HardDrive

                       Private model_Renamed As String = Nothing

                       Private type_Renamed As String = Nothing

                       Private serialNo_Renamed As String = Nothing

     

                       Public Property Model() As String

                                 Get

                                          Return model_Renamed

                                 End Get

                                 Set(ByVal value As String)

                                          model_Renamed = value

                                 End Set

                       End Property

     

                       Public Property Type() As String

                                 Get

                                          Return type_Renamed

                                 End Get

                                 Set(ByVal value As String)

                                          type_Renamed = value

                                 End Set

                       End Property

     

                       Public Property SerialNo() As String

                                 Get

                                          Return serialNo_Renamed

                                 End Get

                                 Set(ByVal value As String)

                                          serialNo_Renamed = value

                                 End Set

                       End Property

              End Class

     

              Friend Class TestProgram

             

                       <STAThread> _

                       Shared Sub Main(ByVal args As String())

                                 Dim hdCollection As ArrayList = New ArrayList()

     

                                 Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")

     

                                 For Each wmi_HD As ManagementObject In searcher.Get()

                                          Dim hd As HardDrive = New HardDrive()

                                          hd.Model = wmi_HD("Model").ToString()

                                          hd.Type = wmi_HD("InterfaceType").ToString()

     

                                          hdCollection.Add(hd)

                                 Next wmi_HD

     

    searcher = New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")

     

                                 Dim i As Integer = 0

                                 For Each wmi_HD As ManagementObject In searcher.Get()

                                          ' get the hard drive from collection

                                          ' using index

                                          Dim hd As HardDrive = CType(hdCollection(i), HardDrive)

     

                                          ' get the hardware serial no.

                                          If wmi_HD("SerialNumber") Is Nothing Then

                                                    hd.SerialNo = "None"

                                          Else

                                          hd.SerialNo = wmi_HD("SerialNumber").ToString()

                                          End If

     

                                          i += 1

                                 Next wmi_HD

     

                                 ' Display available hard drives

                                 For Each hd As HardDrive In hdCollection

    Console.WriteLine("Model" & Constants.vbTab + Constants.vbTab & ": " & hd.Model)

    Console.WriteLine("Type" & Constants.vbTab + Constants.vbTab & ": " & hd.Type)

    Console.WriteLine("Serial No." & Constants.vbTab & ": " & hd.SerialNo)

    Console.WriteLine()

                                 Next hd

     

                                 ' Pause application

                                 Console.WriteLine("Press [Enter] to exit...")

                                 Console.ReadLine()

                       End Sub

              End Class

    End Namespace

     

     

    If you need the entire source program, please tell me your mailbox, I will send it to you.

     

     

    Regards,

    Martin

    Tuesday, October 9, 2007 9:52 AM
  • Similarly, get the serial number of the motherboard like this:

    Add Reference to System.Management.dll.

    Add Imports system.Management at the top of your source code.

    Code Block

    Imports System.Management

    Module Module1

     

        Sub Main()

     

            Dim oConn As ConnectionOptions = New ConnectionOptions

            oConn.Username = "Administrator"

            oConn.Password = "password"

            Dim oMs As System.Management.ManagementScope = New System.Management.ManagementScope("\\machineID", oConn)

            Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select SerialNumber from Win32_BaseBoard")

            Dim oSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(oMs, oQuery)

            Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get

            For Each oReturn As ManagementObject In oReturnCollection

                Console.WriteLine(("Serial Number : " + oReturn("SerialNumber").ToString))

            Next

            Console.ReadLine()

        End Sub

     

    End Module

    Reference: Win32_MotherboardDevice Class

    Tuesday, October 9, 2007 10:38 AM
  • Similarly, get the CPU ID like this:

    Add Reference to System.Management.dll.

    Add Imports system.Management at the top of your source code.

    Code Block

    Imports System.Management

    Module Module1

     

        Sub Main()

     

            Dim cpuInfo As String = String.Empty

            Dim temp As String = String.Empty

            Dim mc As ManagementClass = New ManagementClass("Win32_Processor")

            Dim moc As ManagementObjectCollection = mc.GetInstances

            For Each mo As ManagementObject In moc

                If (cpuInfo = String.Empty) Then

                    ' only return cpuInfo from first CPU

                    cpuInfo = mo.Properties("ProcessorId").Value.ToString

                    Console.WriteLine(("CPU ID : " & cpuInfo))

                End If

            Next

            Console.ReadLine()

        End Sub

     

    End Module

     

    By the way, here is another good source-opened sample.

    How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...)

     

    Best wishes,

    Martin Xie

    Tuesday, October 9, 2007 10:52 AM
  •  

    Thanks All it works fine

    ''

    I've a small question please

    (((cpuInfo = mo.Properties("ProcessorId").Value.ToString)))

    I nedd other mo.Properties Members

     

    Is ProcessorId Means the Serial Number ?

    Monday, January 7, 2008 12:18 PM
  • Hi ahmed,

     

    Thank you for your feedback.

     

    ProcessorId doesn't mean the Serial Number.

     

    CPUID details:

    http://msdn2.microsoft.com/en-us/library/hskdteyh(vs.80).aspx

    Generates the cpuid instruction available on x86 and x64, which queries the processor for information about the supported features and CPU type.

     

    The supported features and CPU type information is returned in CPUInfo, an array of four 32-bit integers that is filled with the values of the EAX, EBX, ECX, and EDX registers (in that order) after the cpuid instruction is called.

    The information returned has a different meaning depending on the value passed as the InfoType parameter. The information returned with various values of InfoType is processor-dependent.

     

    The following table shows the meaning of the Feature Information value, the value of EDX which is written to CPUInfo[3], when the InfoType argument is 1.

    Feature Information Returned

    Bit

    Mnemonic

    Description

    18

    PSN

    Processor Serial Number

    Monday, January 7, 2008 1:46 PM
  • This works fine with Win Xp and above but it is not supporting Win 2K.

    and also it required admin previleges on PC to get serial.

     

    Can U help me get out of these problems,

     

    Sanjay

     

    Saturday, February 23, 2008 11:01 AM
  • Hi Martin,

     

    Pls send me the source code. My email id is rajeev.acpl@aol.in

     

    regards

    rajeev

     

    Saturday, February 23, 2008 12:36 PM
  • Hi Martin:

     

    I am trying to test this code in Windows Vista and it doesn't run. Please send complet code to baltasar@melpi.com and tell me the way to get the serial number of a hard disk (ide/sata) on Windows Vista.

     

    Thank you. I hope your answer.

     

    Tuesday, March 4, 2008 10:53 AM
  • Yes please, send me the entire source program

    thanks

     

     

    Tuesday, April 22, 2008 7:19 AM
  •  

    Yes please, send me the entire source program to fredrik@landreus.com

    thanks

    Tuesday, April 22, 2008 7:05 PM
  • Can you send your entire source program to info@fea4you.com.

     

    Thank you.

     

    Tuesday, September 30, 2008 6:03 PM
  • How i can do it using C/C++ ??? Please give me link or ask my quesion
    Sunday, November 23, 2008 8:26 PM
  •  

    Yes I'm interested in the souce code. djrick1996@msn.com
    Sunday, November 30, 2008 6:52 PM
  • Hi Martin,
    i can not retrieve the serialnumber of my motherboard. It`s only a string with a lot of spaces ("                 ").
    I also tried your solution, but i had problem with this line

      
    Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get



    thanks for your help.
    rabarberapa
    Sunday, March 7, 2010 12:29 PM
  • please tell how it can be done in c++
    Saturday, May 22, 2010 7:03 AM
  • If you get the answer please let me too know at ninadpchaudhari@live.in
    Saturday, May 22, 2010 7:06 AM
  • Hello

     

    I want to get the CPU ID , Hard Disk ID and MAC ID of my computer.

    There is an inline assembly function for CPU ID in VS C++ called __cpuid(CPU_ID, i); but it gives a lot of unnecessary information and is difficult to sort.

    my email is anuradha.amrutkar@iitb.ac.in

    I would prefer it in VS C++

    Please send me the entire source code for the above requirement

     

    Thank you in advance 

    Thursday, June 24, 2010 1:46 PM
  • Hi Martin: I've tried win32_physicalmedia on my system but it only returned one of three serial numbers. All three hard drives are WDs, exactly the same capacity and model. The codes were in VBA and VBscript. Also can you help me convert your code for mainboard serial into VBA? I intend to run it on Access. Thanks.
    Sunday, November 21, 2010 8:38 AM
  •  

    How to get the serial of my motherboard or hard or cpu

     

    thanks


    Sunday, July 10, 2011 3:48 AM
  • i am the beginner in this,

    may i know how to use this code.

    can you explain it from scratch.

    (even i need to know my motherboard and processor serial number)

    Tuesday, February 7, 2012 12:57 PM
  • You did great work ! but,

    Its all the long process.

    we can just get the details of motherboard bios serial number using a small command.

    go to run

    type "cmd" -> ok

    now u will get command prompt/ DOS

    now u can type the following command with out quotes exactly.

    "wmic bios get serialnumber"

    You will get ur bios serial number i.e your motherboard manufacturer number.

    Thankyou.


    Wednesday, June 27, 2012 3:52 PM
  • I think no need of user credentials for user computer. If it does not exist. 

    I tried it works fine.

    but rather than that we can use a simple command in DOS.

    wmic bios get serialnumberc

    Thankyou

    Wednesday, June 27, 2012 3:55 PM