/// <summary> /// 获取硬盘ID /// </summary> /// <returns></returns> public static String GetDriverID() { String HDid; ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc1 = cimobject1.GetInstances(); foreach (ManagementObject mo in moc1) { HDid = (string)mo.Properties["Model"].Value; return(HDid.ToString()); } return(""); }
/// <summary> /// 获取硬件信息 /// </summary> /// <returns></returns> private string GetHardWareInfo() { StringBuilder sbRet = new StringBuilder(); string cpuInfo = "";//cpu序列号 ManagementClass cimobject = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = cimobject.GetInstances(); foreach (ManagementObject mo in moc) { cpuInfo = mo.Properties["ProcessorId"].Value.ToString(); sbRet.Append(cpuInfo.ToString());//"cpu序列号:" + //Response.Write("cpu序列号:" + cpuInfo.ToString()); } //获取硬盘ID String HDid; ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc1 = cimobject1.GetInstances(); foreach (ManagementObject mo in moc1) { HDid = (string)mo.Properties["Model"].Value; //Response.Write("硬盘序列号:" + HDid.ToString()); sbRet.Append("-" + HDid.ToString());//;硬盘序列号: } //获取网卡硬件地址 //ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); //ManagementObjectCollection moc2 = mc.GetInstances(); //foreach (ManagementObject mo in moc2) //{ // if ((bool)mo["IPEnabled"] == true) // { // //Response.Write("MAC address\t{0}" + mo["MacAddress"].ToString()); // string dd = mo.Properties["MacAddress"].Value.ToString(); // if (!sbRet.ToString().Contains(mo["MacAddress"].ToString())) // { // sbRet.Append("-" + mo["MacAddress"].ToString());//;MAC address\t{0} // } // mo.Dispose(); // } //} return(sbRet.ToString()); }
private void GetInfo() { string cpuInfo = "";//cpu序列号 ManagementClass cimobject = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = cimobject.GetInstances(); foreach (ManagementObject mo in moc) { cpuInfo = mo.Properties["ProcessorId"].Value.ToString(); this.label1.Text = "cpu序列号:" + cpuInfo.ToString(); } //获取硬盘ID String HDid; ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc1 = cimobject1.GetInstances(); foreach (ManagementObject mo in moc1) { HDid = (string)mo.Properties["Model"].Value; this.label2.Text = "硬盘序列号:" + HDid.ToString(); } //获取网卡硬件地址 ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc2 = mc.GetInstances(); string strTmp = ""; int i = 0; foreach (ManagementObject mo in moc2) { if ((bool)mo["IPEnabled"] == true) { strTmp = strTmp + "MAC address\t{" + i.ToString() + "}" + mo["MacAddress"].ToString() + "\r\n"; } i++; mo.Dispose(); } this.label3.Text = strTmp; }