using System.Management;
查找CPU编号比较耗时.最好在其他线程调用.
硬盘编号还快一些,但是分区后会变.如果硬盘克隆.硬盘编号也一样
方法如下:
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
/// <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;
}