无法在客户端计算机中获取硬盘驱动器号

时间:2018-10-10 15:35:17

标签: c# wmi

我正在开发机器上的类为System.management的c#项目中检索硬盘制造商序列号。

但是,当我将该程序部署到客户端计算机上时,我无法检索到硬盘号,而无法在硬盘号宫中获得值4c354541464134542202020202020202020220202020202

我还在自己的设置中添加了system.management.dll,但仍然无法获取硬盘号。

我的代码是:

ManagementObjectSearcher moSearcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

foreach (ManagementObject wmi_HD in moSearcher.Get())
{
    ArrayList hardDriveDetails = new ArrayList();
    HardDrive hd = new HardDrive();  // User Defined Class
    hd.Model = wmi_HD["Model"].ToString();  //Model Number
    hd.Type = wmi_HD["InterfaceType"].ToString();  //Interface Type
    hd.SerialNo = wmi_HD["SerialNumber"].ToString(); //Serial Number
    hardDriveDetails.Add(hd);
    // label1.Text = "Model : " + hd.Model;
    //label2.Text = " Type : " + hd.Type;
    label5.Text = "Your serial no. is: " + hd.SerialNo.Trim();
    // MessageBox.Show(hd.SerialNo);

    if (hd.SerialNo.Trim().Equals("WDEESC4E"))
    {
       // btnDownload.Enabled = true;
        //btnImport.Enabled = true;
        //btnShow.Enabled = true;
        btnValidate.Enabled = true;
        btnReset.Enabled = true;


    }
    else
    {
        MessageBox.Show("Please activate software.");
        btnDownload.Enabled = false;
        btnImport.Enabled = false;
        btnShow.Enabled = false;
        btnValidate.Enabled = false;
        btnReset.Enabled = false;

    }

}

0 个答案:

没有答案