/// <summary>
/// 1.获取CPU序列号代码
/// </summary>
public static string GetCpuID()
{
try
{
string cpuInfo = string.Empty;//cpu序列号
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor");
foreach (ManagementObject mo in searcher.Get())
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString().Trim();
break;
}
if (string.IsNullOrEmpty(cpuInfo))
cpuInfo = "unknow";
return cpuInfo;
}
catch(Exception ex)
{
return "unknow";
}
}
/// <summary>
/// 3.获取硬盘ID
/// </summary>
public static string GetDiskID()
{
//取第一块硬盘编号
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
string strHardDiskID = string.Empty;
foreach (ManagementObject mo in searcher.Get())
{
strHardDiskID = mo.Properties["SerialNumber"].Value.ToString().Trim();
break;
}
if (string.IsNullOrEmpty(strHardDiskID))
strHardDiskID = "unknow";
return strHardDiskID;
}
catch (Exception ex)
{
return "unknow";
}
}
我做测试 一个机器上获取不到cpu序列号 另外一个机器上获取不到硬盘物理序列号,我在网上看了一下 ,基本上都是转贴的 内容都是一样的 ,没有找到说是有这种问题的 ,还请知道怎么做的高手帮忙看一下 小弟不胜感激!
获取CPUID
public static string FindComputerCPU_ID()
{
ManagementScope ms = new ManagementScope("root\\cimv2");
ms.Connect();
ManagementObjectSearcher sysinfo = new ManagementObjectSearcher(ms, new SelectQuery("Win32_Processor"));
string cpuId = "";
foreach (ManagementObject sys in sysinfo.Get())
{
cpuId = sys["ProcessorId"].ToString();
}
return cpuId;
}