using System.Management;
查找CPU编号比较耗时.最好在其他线程调用.
硬盘编号还快一些,但是分区后会变.如果硬盘克隆.硬盘编号也一样
方法如下:
View Code
/// <summary>
/// 取CPU编号
/// </summary>
/// <returns></returns>
public String GetCpuID()
{
try
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
String strCpuID = null;
foreach (ManagementObject mo in moc)
{
strCpuID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strCpuID;
}
catch
{
return "szzx";
}
}//end method
public string GetDisk()
{
// 获取硬盘信息
string _HDInfo = "";
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
_HDInfo = (string)mo.Properties["Model"].Value;
}
return _HDInfo;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步