检索设备的serialno

时间:2012-10-29 10:42:28

标签: c# windows wmi serial-number

我无法从serialno中选择Win32_DiskDrive。当我正在调试它时,它显示我“未找到”

代码如下:

string serialno="";
ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM     Win32_DiskDrive");

foreach (ManagementObject moDisk in mosDisks.Get())
{
  serialno = moDisk["SerialNumber"].ToString();

  dataGridView1.Columns[4].HeaderText = "SerialNo";
  dataGridView1.Columns[4].DataPropertyName = serialno;
  row.Cells[4].Value = dataGridView1.Columns[4].DataPropertyName;
}

1 个答案:

答案 0 :(得分:1)

您可以尝试使用此代码 - 基于Win32_PhysicalMedia

  var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
   foreach(ManagementObject wmi_HD in searcher.Get())
   {
       var serialno = wmi_HD["SerialNumber"].ToString();
   }

链接:http://msdn.microsoft.com/en-us/library/windows/desktop/aa394346(v=vs.85).aspx