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

一段获取硬盘序列号的代码,哪里错了
C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace 显示cpu信息
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_PhysicalMedia");
            String strHardDiskID = null;
            foreach (ManagementObject mo in searcher.Get()) {
                strHardDiskID = mo["SerialNumber"].ToString().Trim();                
break;
            }
            textBox8.Text = strHardDiskID;
        }

       
    }
}



strHardDiskID = mo["SerialNumber"].ToString().Trim();这行报错,提示:未将对象引用设置到对象的实例

------解决方案--------------------
探讨

引用:
引用:

引用:
引用:

引用:
引用:
C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using Sys……