这篇文章主要介绍了c# 获取计算机硬件信息的示例代码,帮助大家更好的理解和学习c#,感兴趣的朋友可以了解下
/// <summary>
/// 获取CPU的编号
/// </summary>
/// <returns>CPU的编号</returns>
public static List<string> GetCPUID()
{
List<string> lstInfo =new List<string>();
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
string cpuInfo = mo.Properties["ProcessorId"].Value.ToString();//cpu序列号
lstInfo.Add(cpuInfo);
}
return lstInfo;
}
/// <summary>
/// 获取硬件信息
/// </summary>
/// <returns>硬件信息集合</returns>
public static List<string> GetHardDiskInfo()
{
List<string> lstInfo = new List<string>();
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
string HDid = (string)mo.Properties["Model"].Value;
lstInfo.Add(HDid);
}
return lstInfo;
}
/// <summary>
/// 获取Mac地址
/// </summary>
/// <returns>Mac地址集合</returns>
public static List<string> GetMacAddress()
{
List<string> lstInfo = new List<string>();
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
lstInfo.Add(mo["MacAddress"].ToString());
}
mo.Dispose();
}
return lstInfo;
}
/// <summary>
/// 获取主板信息
/// </summary>
/// <returns>主板信息集合</returns>
public static List<string> GetBoard()
{
List<string> lstInfo = new List<string>();
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_baseboard");
foreach (ManagementObject mo in mos.Get())
{
lstInfo.Add(mo["SerialNumber"].ToString());
break;
}
return lstInfo;
}
以上就是c# 获取计算机硬件信息的示例代码的详细内容,更多关于c# 获取硬件信息的资料请关注得得之家其它相关文章!
沃梦达教程
本文标题为:c# 获取计算机硬件信息的示例代码
基础教程推荐
猜你喜欢
- C# 调用WebService的方法 2023-03-09
- C# windows语音识别与朗读实例 2023-04-27
- ZooKeeper的安装及部署教程 2023-01-22
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- 一个读写csv文件的C#类 2022-11-06
- C#控制台实现飞行棋小游戏 2023-04-22
- C#类和结构详解 2023-05-30
- C# List实现行转列的通用方案 2022-11-02
- unity实现动态排行榜 2023-04-27
- winform把Office转成PDF文件 2023-06-14