本文介绍了如何在C#桌面应用程序中获取BIOS信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
请任何人告诉我如何在C#桌面应用程序中获取BIOS编号,硬盘编号,主板编号
hey guys
pls any one tell me to how to get bios no, hard disk no, mother board no in the c# desktop application
推荐答案
using Microsoft.Win32;
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(@"\\.\root\cimv2",
"SELECT * FROM Win32_BIOS"));
foreach (var _object in searcher.Get())
{
if (_object != null)
{
try
{
string object_name = "?";
if (_object["Name"] != null)
{
object_name = _object["Name"].ToString();
}
else if (_object["Caption"] != null)
{
object_name = _object["Caption"].ToString();
}
else if (_object["Description"] != null)
{
object_name = _object["Description"].ToString();
}
foreach (var property in _object.Properties)
{
string property_name = property.Name;
if ((property.Value != null) &&
(!property_name.Contains("CreationClassName")))
{
string property_value;
if (!(property.Value is Array))
{
property_value = property.Value.ToString();
}
else
{
StringBuilder _property_value = new StringBuilder();
Array _property_array = property.Value as Array;
int count = 0;
foreach (var entry in _property_array)
{
if (count > 0) _property_value.Append(",\r\n");
_property_value.Append(entry.ToString());
count++;
}
property_value = _property_value.ToString();
}
}
}
}
catch (ManagementException exception)
{
System.Diagnostics.Trace.WriteLine(exception.ToString());
}
}
}
此逻辑显示如何枚举WMI中有关BIOS的大多数信息.
This logic shows how to enumerate most of the information available in WMI about the BIOS.
这篇关于如何在C#桌面应用程序中获取BIOS信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!