c#是不是无法有效获取cpu序列号?
如题,使用cpu+硬盘序列号获取机器码做注册用的
问题是cpu序列号有时候无法获取,是不是双核cpu并不能有效保证一直可以获取?
代码如下:
/// <summary>
/// 获取硬盘卷标号
/// </summary>
/// <returns></returns>
public string GetDiskVolumeSerialNumber()
{
ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid="c:"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
/// <summary>
/// 获取CPU序列号
/// </summary>
/// <returns></returns>
public string GetCpu()
{
string strCpu = null;
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuCollection = myCpu.GetInstances();
foreach (ManagementObject myObject in myCpuCollection)
{
strCpu = myObject.Properties["Processorid"].Value.ToString();
}
return strCpu;
}