1 /// <summary> 2 /// 顯示MAC地址 3 /// </summary> 4 /// <returns></returns> 5 private string GetMAC() 6 { 7 string mac = "本機的MAC地址:"; 8 using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration")) 9 { 10 ManagementObjectCollection moc = mc.GetInstances(); 11 foreach (ManagementObject mo in moc) 12 { 13 if ((bool)mo["IPEnabled"]) 14 { 15 string[] tmpMac = mo["MacAddress"].ToString().Split(':'); 16 for (int i = 0; i < tmpMac.Length; i++) 17 { 18 mac += tmpMac[i]; 19 } 20 } 21 } 22 } 23 return mac + "\r\n"; 24 } 25 26 /// <summary> 27 /// 獲取本機CPU序列號 28 /// </summary> 29 /// <returns></returns> 30 private string GetCPUID() 31 { 32 string CPUID = "本機的CPU序列號:"; 33 using (ManagementClass mc = new ManagementClass("Win32_Processor")) 34 { 35 ManagementObjectCollection moc = mc.GetInstances(); 36 foreach (ManagementObject item in moc) 37 { 38 CPUID += item["ProcessorId"].ToString().Trim(); 39 } 40 } 41 return CPUID + "\r\n"; 42 } 43 44 /// <summary> 45 /// 獲取本機硬盤序列號 46 /// </summary> 47 /// <returns></returns> 48 private string GetHardID() 49 { 50 string HardID = "本機的CPU序列號:"; 51 using (ManagementClass mc = new ManagementClass("Win32_DiskDrive")) 52 { 53 ManagementObjectCollection moc = mc.GetInstances(); 54 foreach (ManagementObject item in moc) 55 { 56 HardID += item["Model"].ToString().Trim(); 57 } 58 } 59 return HardID + "\r\n"; 60