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 errorCode、文字列の多分フルパス) で

System.IO.__Error.WinIODriveError (文字列 driveName、Int32 errorCode) で

System.IO.DriveInfo.get_DriveFormat() で

USB_Data_Protector.Form1.getdriverinfo() で

これは私のラップトップでエラーなく正常に動作します。仮想PCまたは別のPCで実行すると、このエラーが表示されます。

4

1 に答える 1

5

DriveFormat にアクセスする前に、次のことを確認できますか? IsReady プロパティ

driveInfo.IsReady
于 2012-01-25T04:38:31.543 に答える