c# 获取本机 MAC地址序列号硬盘序列号

it2022-05-05  123

View Code   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 

转载于:https://www.cnblogs.com/angleSJW/archive/2011/06/07/2074547.html

相关资源:C#查询本机唯一识别码 硬盘卷标号 BIOS序列号

最新回复(0)