c# 获取计算机硬件信息的示例代码

时间:2021-05-20

/// <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# 获取硬件信息的资料请关注其它相关文章!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章