C# – Device is not ready error on DriveInfo.DriveFormat

cdriveinfo

i have that method that retrieve the removable devices information which are 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();       
    }

This error occurs:

System.IO.IOException: The device is not ready.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.IO.__Error.WinIODriveError(String driveName, Int32 errorCode)

at System.IO.DriveInfo.get_DriveFormat()

at USB_Data_Protector.Form1.getdriverinfo()

This works fine on my laptop with no errors. When it's run on virtual pc or another pc, this error shows.

Best Answer

Can you check the following before you access the DriveFormat? IsReady Property

driveInfo.IsReady