如何在不接收空字符串的情况下获取主板ID
How to get motherboard ID without receiving empty strings?
我尝试了很多东西:
//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;
}
这在我的电脑上都是空字符串,但在笔记本电脑上是正确的ID。另一些人也报告了两台电脑是空的主板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#上找到工作解决方案
有些主板根本没有ID。它设置为空字符串。所以,如果有人需要使用主板独特的东西进行许可,他们应该收到主板UUID。
就我个人而言,我建议使用这个特定的开源硬件监视器库(您需要源代码)。您可以使用它进行硬件识别。打开硬件监视器
还有一个名为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();
愿原力与你同在。
相关文章:
- 如何在没有实例的情况下获取非静态方法的类型?
- 如何在不等待检索的情况下获取C++中的内存位置?
- 如何在不为其声明变量的情况下获取和使用常量值的地址?
- 在不使用模板的情况下获取 std::array 引用
- 在确定有实现的情况下获取HTTP 501未实现
- 如何将左值传递给函数,仅在没有模板的情况下获取右值
- 如何在不创建实例的情况下获取类的方法成员的类型?
- 如何在不包含 Windows.h 的情况下获取 IsDebuggerPresent 的声明
- <int> 在不破坏堆栈的情况下获取 C++ 中的堆栈总和
- 如何在不引起实例化的情况下获取功能模板的签名
- 如何在不定义其他 fonction getValue() 的情况下获取私有值
- 如何在不获取所有html的情况下获取QTextEdit的html标签?
- 在不发送任何内容的情况下获取功能的返回
- LDAP函数中是否有任何功能可以在不使用ldap_search的情况下获取用户信息
- 如何在不使用QMediaPlayer的情况下获取Qt中音频和视频文件的持续时间
- 我可以在不声明变量类型的情况下获取输入,或者在 c++ 中为同一变量声明多个类型吗?
- 处理POSIX信号:如何在不使用BackTrace_symbols的情况下获取堆栈跟踪
- 在不知道的情况下获取地图的钥匙
- 在不暂停贪吃蛇游戏的情况下获取输入
- 修复错误:在不更改代码的情况下获取临时地址