2

I tried many things:

//public static string GetMotherBoardID()
//{
//    string mbInfo = String.Empty;

//    //Get motherboard's serial number 
//    ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_BaseBoard");
//    foreach (ManagementObject mo in mbs.Get())
//        mbInfo += mo["SerialNumber"].ToString();

//    return mbInfo;
//}

//public static string GetMotherBoardID()
//{
//    string mbInfo = String.Empty;
//    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)
//    {
//        if (propData.Name == "SerialNumber")
//            mbInfo = String.Format("{0,-25}{1}", propData.Name, Convert.ToString(propData.Value));
//    }

//    return mbInfo;
//}

public static string GetMotherBoardID()
{
    string mbInfo = String.Empty;
    ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_BaseBoard");
    ManagementObjectCollection moc = mbs.Get();
    ManagementObjectCollection.ManagementObjectEnumerator itr = moc.GetEnumerator();

    itr.MoveNext();
    mbInfo = itr.Current.Properties["SerialNumber"].Value.ToString();

    var enumerator = itr.Current.Properties.GetEnumerator();

    if (string.IsNullOrEmpty(mbInfo))
        mbInfo = "0";

    return mbInfo;
}

This all gives empty string on my PC, but the correct ID on the laptop. Some other person also reporting on two PCs is empty motherboard ID.

The result of:

public static string GetMotherBoardID()
{
    string mbInfo = String.Empty;
    ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_BaseBoard");
    ManagementObjectCollection moc = mbs.Get();
    ManagementObjectCollection.ManagementObjectEnumerator itr = moc.GetEnumerator();

    itr.MoveNext();
    mbInfo = itr.Current.Properties["SerialNumber"].Value.ToString();

    var enumerator = itr.Current.Properties.GetEnumerator();

    string properties = "";

    while (enumerator.MoveNext())
    {
        properties += "[" + enumerator.Current.Name + "][" + (enumerator.Current.Value != null ? enumerator.Current.Value.ToString() : "NULL") + "]\n";
    }

    if (string.IsNullOrEmpty(mbInfo))
        mbInfo = "0";

    return mbInfo;
}
[Caption][Основная плата]
[ConfigOptions][NULL]
[CreationClassName][Win32_BaseBoard]
[Depth][NULL]
[Description][Основная плата]
[Height][NULL]
[HostingBoard][True]
[HotSwappable][False]
[InstallDate][NULL]
[Manufacturer][Gigabyte Technology Co., Ltd.]
[Model][NULL]
[Name][Основная плата]
[OtherIdentifyingInfo][NULL]
[PartNumber][NULL]
[PoweredOn][True]
[Product][H55M-S2H]
[Removable][False]
[Replaceable][True]
[RequirementsDescription][NULL]
[RequiresDaughterBoard][False]
[SerialNumber][ ]
[SKU][NULL]
[SlotLayout][NULL]
[SpecialRequirements][NULL]
[Status][OK]
[Tag][Base Board]
[Version][x.x]
[Weight][NULL]
[Width][NULL]

Maybe c# is bad for retrieving such things? I hope for solution on C/C++ or working solution on C#

Kosmo零
  • 4,001
  • 9
  • 45
  • 88
  • Why don't you actually iterate over the iterator you obtain from `ManagementObjectCollection` and see if the proper value is in it? Right now you're just getting the second object in the collection and casting that to a string, which may be empty. It's probably not the same entry of the collection across all machines. – aevitas Jul 29 '13 at 14:41
  • I tried that, but those are really empty. Well, technically this - " " – Kosmo零 Jul 29 '13 at 14:42
  • itr.MoveNext() works only once. So, there is single object – Kosmo零 Jul 29 '13 at 14:52
  • Are you sure there is a valid motherboard ID, I believe a lot of this information is at the discretion of the manufacturer. I would try to verify with another application or method before jumping off of the deep end. – Mark Hall Feb 09 '14 at 05:50

3 Answers3

2

Some motherboards simply don't have ID. It set to empty string. So, if someone need to use motherboard unique thing for licensing purposes they should receive motherboard UUID.

Kosmo零
  • 4,001
  • 9
  • 45
  • 88
1

Personally, I'd recommend using this particular Open Source hardware monitor library (you'll need the source). You can use it for hardware identification. Open Hardware Monitor

Daniel Lane
  • 2,575
  • 2
  • 18
  • 33
0

There is also a NuGet package called DeviceID. However, you will need to include their DLL with your package, but is a great fast, simple solution.

Here a usage example:

 /* Depends on https://www.nuget.org/packages/DeviceId/ Install-Package DeviceId - Version 5.2.0*/
/* Using AddMacAddress(true, true) to exclude both virtual and wireless network adapters. */ 

readonly string MachineSupportID = new DeviceIdBuilder()
    .AddMacAddress(true, true)
    .AddMotherboardSerialNumber()
    .AddProcessorId()
    .AddSystemDriveSerialNumber()
    .ToString();

May the force be with you.

vicsar
  • 301
  • 5
  • 16