How to obtain motherboard serial number
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: How to obtain motherboard serial number

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    3

    How to obtain motherboard serial number

    Hi everyone

    I want to programatically get the serial number of my motherboard (the same that which I can get using programs like "Everest")

    I tried to find it using WMI but Win32_BaseBoard.SerialNumber contains only bios upgrade date and Win32_MotherBoard.DeviceID contains a word "Motherboard"

    Does anyone know how to do it?

    Thanks in advance

  2. #2
    Join Date
    May 2008
    Posts
    1

    Re: How to obtain motherboard serial number

    It seems like Win32_BaseBoard.SerialNumber is what you're looking for.

    In python it works with this.

    >>> import wmi
    >>> a = wmi.WMI()
    >>> a.Win32_BaseBoard()[0].SerialNumber

    then it prints your baseboard serial number, the same as everest.

  3. #3
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,477

    Re: How to obtain motherboard serial number

    Try calling IWbemServices->GetObject(...) using "Win32_BaseBoard.Tag=\"Base Board\"" as the class name.

    [Edit] Oops, that's C++. I'll see if I can dig up the C# approach.

  4. #4
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,477

    Re: How to obtain motherboard serial number

    Here you go

    Code:
    namespace Wmi
    {
    	class Program
    	{
    		static void Main( string[ ] args )
    		{
    			ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
    			scope.Connect();
    
    			ManagementObject wmiClass = new ManagementObject( scope, new ManagementPath( "Win32_BaseBoard.Tag=\"Base Board\"" ), new ObjectGetOptions( ) );
    
    			foreach( PropertyData propData in wmiClass.Properties )
    			{
    				Console.WriteLine( String.Format( "{0,-25}{1}", propData.Name, Convert.ToString( propData.Value ) ) );
    			}
    		}
    	}
    }
    and the output:

    Code:
    Caption                            Base Board
    ConfigOptions
    CreationClassName         Win32_BaseBoard
    Depth
    Description                       Base Board
    Height
    HostingBoard                   True
    HotSwappable
    InstallDate
    Manufacturer                    Dell Inc.
    Model
    Name                                Base Board
    OtherIdentifyingInfo
    PartNumber
    PoweredOn                       True
    Product                             0YD479
    Removable
    Replaceable
    RequirementsDescription
    RequiresDaughterBoard
    SerialNumber                    .4QNC2B1.CN1356164F2316.
    SKU
    SlotLayout
    SpecialRequirements
    Status
    Tag                                    Base Board
    Version
    Weight
    Width

  5. #5
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: How to obtain motherboard serial number

    Hi !

    Maybe it should be mentioned that you need to add namespace System.Management. This is done in rightclicking to the references and there add reference. Then you'll get a list and here select System.Manegement.
    In the code then add
    Code:
    using System.Management;
    My question to Arjay regarding this code is: Where to study all the formating issues like
    Code:
    String.Format( "{0,-25}{1}", ...
    Especially whats the meaning of '-25 ' there ?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  6. #6
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,477

    Re: How to obtain motherboard serial number

    Quote Originally Posted by JonnyPoet
    My question to Arjay regarding this code is: Where to study all the formating issues like
    Code:
    String.Format( "{0,-25}{1}", ...
    Especially whats the meaning of '-25 ' there ?
    Jonny, the -25 just pads the string with the default padding character (of a space). The output should have been all vertically aligned in a column, but it got messed up when I posted it here.

    From String.Format(...) in Msdn:

    "The syntax of a format item is {index[,alignment][:formatString]}, which specifies a mandatory index, the optional length and alignment of the formatted text, and an optional string of format specifier characters that govern how the value of the corresponding object is formatted. The components of a format item are:

    index
    A zero-based integer that indicates which element in a list of objects to format. If the object specified by index is a null reference (Nothing in Visual Basic), then the format item is replaced by the empty string ("").

    alignment
    An optional integer indicating the minimum width of the region to contain the formatted value. If the length of the formatted value is less than alignment, then the region is padded with spaces. If alignment is negative, the formatted value is left justified in the region; if alignment is positive, the formatted value is right justified. If alignment is not specified, the length of the region is the length of the formatted value. The comma is required if alignment is specified.

    formatString
    An optional string of format specifiers. If formatString is not specified and the corresponding argument implements the IFormattable interface, then a null reference (Nothing in Visual Basic) is used as the IFormattable.ToString format string. Therefore, all implementations of IFormattable.ToString are required to allow a null reference (Nothing in Visual Basic) as a format string, and return default formatting of the object representation as a String object. The colon is required if formatString is specified.

    The leading and trailing brace characters, '{' and '}', are required. To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".
    "

  7. #7
    Join Date
    Sep 2013
    Posts
    1

    Re: How to obtain motherboard serial number

    Quote Originally Posted by loluengo View Post
    It seems like Win32_BaseBoard.SerialNumber is what you're looking for.

    In python it works with this.

    >>> import wmi
    >>> a = wmi.WMI()
    >>> a.Win32_BaseBoard()[0].SerialNumber

    then it prints your baseboard serial number, the same as everest.
    Does python have an equivalent module for Linux ?..I could retrieve the baseboard serial no. using dmidecode command, but it requires root privileges..is there any way by which i could retrieve it w/o root privileges ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center