2

我尝试了很多事情:

//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;
}

这一切都在我的 PC 上给出了空字符串,但在笔记本电脑上给出了正确的 ID。其他人也报告两台 PC 是空的主板 ID。

的结果:

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]

也许 c# 不适合检索这些东西?我希望 C/C++ 上的解决方案或 C# 上的工作解决方案

4

3 回答 3

2

有些主板根本没有ID。它设置为空字符串。因此,如果有人需要使用主板独特的东西来获得许可,他们应该收到主板 UUID。

于 2014-02-21T11:02:47.273 回答
1

就个人而言,我建议使用这个特定的开源硬件监视器库(您需要源代码)。您可以将其用于硬件识别。打开硬件监视器

于 2013-07-29T14:54:14.070 回答
0

还有一个名为DeviceID的 NuGet 包。但是,您需要在您的包中包含他们的 DLL,但这是一个非常快速、简单的解决方案。

这里是一个使用示例:

 /* 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();

愿原力与你同在。

于 2021-05-30T16:19:37.260 回答