我有那种检索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:设备尚未就绪。
at System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath)
at System.IO .__ Error.WinIODriveError(String driveName,Int32 errorCode)
在System.IO.DriveInfo.get_DriveFormat()
在USB_Data_Protector.Form1.getdriverinfo()
这在我的笔记本电脑上工作正常,没有错误。当它在虚拟PC或其他电脑上运行时,会出现此错误。