日期:2014-05-20 浏览次数:20446 次
protected void Button1_Click(object sender, EventArgs e) { Label1.Text = GetCpuId() + "||" + GetDiskID()+ "||" + GetDiskVolumeSerialNumber() + "||" + getCpu2(); } /// <summary> /// 查询CPU编号 /// </summary> public string GetCpuId() { ManagementClass mClass = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = mClass.GetInstances(); string cpuId = null; foreach (ManagementObject mo in moc) { cpuId = mo.Properties["ProcessorId"].Value.ToString(); break; } return cpuId; } public string GetDiskID() { String HDid = null; ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc1 = cimobject1.GetInstances(); foreach (ManagementObject mo in moc1) { HDid = mo.Properties["Model"].Value as string; } return HDid; } public string GetDiskVolumeSerialNumber() { ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\""); disk.Get(); return disk.GetPropertyValue("VolumeSerialNumber").ToString(); } public string getCpu2() { string strCpu = null; ManagementClass myCpu = new ManagementClass("win32_Processor"); ManagementObjectCollection myCpuConnection = myCpu.GetInstances(); foreach (ManagementObject myObject in myCpuConnection) { strCpu = myObject.Properties["Processorid"].Value.ToString(); break; } return strCpu; }