博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

取得CPU 编号

Posted on 2011-05-21 07:59  linFen  阅读(339)  评论(0编辑  收藏  举报

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;
}