标签:style blog color os io ar for div cti
有时候需要得到硬件信息绑定用户登录
代码如下:
1 private string GetProcessSerialNumber() 2 { 3 try 4 { 5 ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher( 6 new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"), 7 new System.Management.ObjectQuery("SELECT * FROM Win32_processor") 8 ).Get(); 9 if (ProcessCollection != null && ProcessCollection.Count > 0) 10 { 11 StringBuilder sb = new StringBuilder(); 12 foreach (ManagementObject mo in ProcessCollection) 13 { 14 sb.Append(mo["ProcessorId"]); 15 } 16 return sb.ToString(); 17 } 18 else 19 { 20 return ""; 21 } 22 } 23 catch (Exception) 24 { 25 return ""; 26 } 27 } 28 29 private string GetMotherBoardSerialNumber() 30 { 31 try 32 { 33 ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher( 34 new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"), 35 new System.Management.ObjectQuery("SELECT * FROM Win32_bios") 36 ).Get(); 37 if (ProcessCollection != null && ProcessCollection.Count > 0) 38 { 39 StringBuilder sb = new StringBuilder(); 40 foreach (ManagementObject mo in ProcessCollection) 41 { 42 sb.Append(mo["SerialNumber"]); 43 } 44 return sb.ToString(); 45 } 46 else 47 { 48 return ""; 49 } 50 } 51 catch (Exception) 52 { 53 return ""; 54 } 55 } 56 57 private string GetHardDisk0SerialNumber() 58 { 59 try 60 { 61 ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher( 62 new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"), 63 new System.Management.ObjectQuery("SELECT * FROM Win32_DiskDrive") 64 ).Get(); 65 if (ProcessCollection != null && ProcessCollection.Count > 0) 66 { 67 StringBuilder sb = new StringBuilder(); 68 foreach (ManagementObject mo in ProcessCollection) 69 { 70 if(mo["Name"].ToString().IndexOf("DRIVE0")!=-1) 71 sb.Append(mo["SerialNumber"]); 72 } 73 return sb.ToString(); 74 } 75 else 76 { 77 return ""; 78 } 79 } 80 catch (Exception) 81 { 82 return ""; 83 } 84 } 85 86 private string GetNetWorkMACSerialNumber() 87 { 88 try 89 { 90 ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher( 91 new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"), 92 new System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration") 93 ).Get(); 94 if (ProcessCollection != null && ProcessCollection.Count > 0) 95 { 96 StringBuilder sb = new StringBuilder(); 97 foreach (ManagementObject mo in ProcessCollection) 98 { 99 if (mo["IPEnabled"].ToString() == "True") 100 sb.Append(mo["MacAddress"]); 101 } 102 return sb.ToString(); 103 } 104 else 105 { 106 return ""; 107 } 108 } 109 catch (Exception) 110 { 111 return ""; 112 } 113 }
标签:style blog color os io ar for div cti
原文地址:http://www.cnblogs.com/maintell/p/3951139.html