//引入命名空间
using System.Management;
//获取硬盘序列号
try { ManagementObjectSearcher cmicWmi = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); UInt32 tmpUint32 = 0; foreach (ManagementObject cmicWmiObj in cmicWmi.Get()) { tmpUint32 = Convert.ToUInt32(cmicWmiObj["signature"].ToString()); } this.DiskID.Text = tmpUint32.ToString(); this.Disk.Text = md5tohash(this.DiskID.Text); //this.gProgressBar1.Value++; } catch (Exception ex1) { throw new Exception(ex1.ToString()); } //获取cpu序列号 try { ManagementObjectSearcher Wmi = new ManagementObjectSearcher("SELECT * FROM Win32_Processor"); string tmpUint32_1 = string.Empty; foreach (ManagementObject WmiObj in Wmi.Get()) { tmpUint32_1 = WmiObj["ProcessorId"].ToString(); } this.CPUID.Text = tmpUint32_1; this.CPU.Text = md5tohash(this.CPUID.Text); //this.gProgressBar1.Value++; } catch (Exception ex2) { throw new Exception(ex2.ToString()); }