获取cpu和硬盘的序列号,得到机器码

        using System.Management;
        using System.Management.Instrumentation;
        
        ///   <summary>    
         ///   获取cpu序列号        
         ///   </summary>    
         ///   <returns> string </returns>    
         public string GetCpuInfo()   
         {   
             string cpuInfo = " ";   
             using (ManagementClass cimobject = new ManagementClass("Win32_Processor"))   
             {   
                 ManagementObjectCollection moc = cimobject.GetInstances();   
   
                 foreach (ManagementObject mo in moc)   
                 {   
                     cpuInfo = mo.Properties["ProcessorId"].Value.ToString();   
                     mo.Dispose();   
                 }   
             }   
             return cpuInfo.ToString();   
         }   
   
         ///   <summary>    
         ///   获取硬盘ID        
         ///   </summary>    
         ///   <returns> string </returns>    
         public string GetHDid()   
         {   
             string HDid = " ";   
             using (ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"))   
             {   
                 ManagementObjectCollection moc1 = cimobject1.GetInstances();   
                 foreach (ManagementObject mo in moc1)   
                 {   
                     HDid = (string)mo.Properties["Model"].Value;   
                     mo.Dispose();   
                 }   
             }   
             return HDid.ToString();   
         }   

 

posted @ 2012-12-08 20:13  jeffrey77  阅读(507)  评论(0编辑  收藏  举报