1

我有检索 NTFS 可移动设备信息的方法:

    private void getdriverinfo()
    {
        // get the usb flash driver
        foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
        {
            if (driveInfo.DriveType == DriveType.Removable && driveInfo.DriveFormat.Equals("NTFS"))
            {
                comboBox1.Items.Add(driveInfo.Name);
            }
        }
        if (comboBox1.Items.Count == 0)
        {
            MessageBox.Show("No Removable Device Found , please plug in the USB drive and make sure it is in NTFS format and retry", "No Device Found!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else if (comboBox1.Items.Count == 1)
        {
            comboBox1.Text = comboBox1.Items[0].ToString();
        }
        else
        {
            MessageBox.Show(comboBox1.Items.Count + " Removable Devices were found , please choose the device you want to protect");
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // get the usb flash driver
        getdriverinfo();       
    }

发生此错误:

System.IO.IOException:设备未准备好。

在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)

在 System.IO.__Error.WinIODriveError(字符串驱动器名称,Int32 错误代码)

在 System.IO.DriveInfo.get_DriveFormat()

在 USB_Data_Protector.Form1.getdriverinfo()

这在我的笔记本电脑上运行良好,没有错误。当它在虚拟电脑或另一台电脑上运行时,会显示此错误。

4

1 回答 1

5

您可以在访问 DriveFormat 之前检查以下内容吗? IsReady 属性

driveInfo.IsReady
于 2012-01-25T04:38:31.543 回答