日期:2014-05-18  浏览次数:21346 次

ManagementClass获取CPU、硬盘序列号信息失败。
public static string[] GetMoc()
  {
  string[]str=new string[4];
  ManagementClass mcCpu=new ManagementClass("win32_Processor");
  ManagementObjectCollection mocCpu=mcCpu.GetInstances();
  foreach(ManagementObject m in mocCpu)
  {
  str[0] = m["ProcessorId"].ToString();
   
  }
   
  ManagementClass mcHD=new ManagementClass("win32_logicaldisk");
  ManagementObjectCollection mocHD=mcHD.GetInstances();
  foreach(ManagementObject m in mocHD)
  {
   
  if (m["DeviceID"].ToString() == "C:")
  {
  str[1] = m["VolumeSerialNumber"].ToString();
  break;
  }
   
   
说明:一般的电脑都能获取到值。只有一两台极其个别的出错,什么原因呢?


------解决方案--------------------
谢谢你老大