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
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.
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.
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
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 ?
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 "}}".
"
Re: How to obtain motherboard serial number
Quote:
Originally Posted by
loluengo
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 ?