Question

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#

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top