kongxx's blog

有困难要上,没有困难创造困难也要上!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#取计算机硬件信息

Posted on 2004-06-09 15:26  kongxx  阅读(3594)  评论(11编辑  收藏  举报
  //取CPU编号
  private String GetCpuID() {
   ManagementClass mc = new ManagementClass("Win32_Processor");
   ManagementObjectCollection moc = mc.GetInstances();
     
   String strCpuID = null ;
   foreach( ManagementObject mo in moc ) {
    strCpuID = mo.Properties["ProcessorId"].Value.ToString();
    break;
   }
   return strCpuID;
  }//end method
 
  //取第一块硬盘编号
  private String GetHardDiskID() {
   ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
   String strHardDiskID = null ;
   foreach(ManagementObject mo in searcher.Get()) {   
    strHardDiskID = mo["SerialNumber"].ToString().Trim();
    break;         
   }
   return strHardDiskID ;
  }//end method