Reading CD Drive causes Message popup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Windows displays a dialog box when I attempt to read files from a CD Drive
and there is not a CD loaded. Anyone know how to stop this dialog from being
displayed?

Following is code used to read drive. drivePath is equal to @"d:\" and d is
my CD rom drive.

Directory.GetFiles ( drivePath, searchPattern );

The dialog box has the following message

"There is no disk in the drive. Please insert a disk into drive D:."

There are three buttions: Cancel, Try Again, and Continue.

Pressing continue causes the following exception.

Source: mscorlib
Exception Type: System.IO.IOException
Message: The device is not ready.
 
I didn't get the windows messagebox on windows 2000. Nevertheless, you could
try skipping the exception:

try {
string[] sfiles = System.IO.Directory.GetFiles(@"E:\", "*.txt");
}
catch(System.IO.IOException ex) {
if(ex.Message == "The device is not ready.\r\n") {
//skip this error..
}
}


hope that helps..
Imran.
 
The dialog is displayed before the exception is thrown.

I did some searching on Google and I saw some threads that said this was a
problem w/version 1.1 of .Net. Version 1.0 of .Net did not have this problem.

Imran Koradia said:
I didn't get the windows messagebox on windows 2000. Nevertheless, you could
try skipping the exception:

try {
string[] sfiles = System.IO.Directory.GetFiles(@"E:\", "*.txt");
}
catch(System.IO.IOException ex) {
if(ex.Message == "The device is not ready.\r\n") {
//skip this error..
}
}


hope that helps..
Imran.

John R. Aldrin said:
Hi,

Windows displays a dialog box when I attempt to read files from a CD Drive
and there is not a CD loaded. Anyone know how to stop this dialog from being
displayed?

Following is code used to read drive. drivePath is equal to @"d:\" and d is
my CD rom drive.

Directory.GetFiles ( drivePath, searchPattern );

The dialog box has the following message

"There is no disk in the drive. Please insert a disk into drive D:."

There are three buttions: Cancel, Try Again, and Continue.

Pressing continue causes the following exception.

Source: mscorlib
Exception Type: System.IO.IOException
Message: The device is not ready.
 
strange - I have framework v1.1. Are you running Windows 2000 or WindowsXP?
I didn't test it on WindowsXP but I sure didn't get the windows messagebox
on windows 2000.

Imran.

John R. Aldrin said:
The dialog is displayed before the exception is thrown.

I did some searching on Google and I saw some threads that said this was a
problem w/version 1.1 of .Net. Version 1.0 of .Net did not have this problem.

Imran Koradia said:
I didn't get the windows messagebox on windows 2000. Nevertheless, you could
try skipping the exception:

try {
string[] sfiles = System.IO.Directory.GetFiles(@"E:\", "*.txt");
}
catch(System.IO.IOException ex) {
if(ex.Message == "The device is not ready.\r\n") {
//skip this error..
}
}


hope that helps..
Imran.

Hi,

Windows displays a dialog box when I attempt to read files from a CD Drive
and there is not a CD loaded. Anyone know how to stop this dialog
from
being
displayed?

Following is code used to read drive. drivePath is equal to @"d:\" and
d
is
my CD rom drive.

Directory.GetFiles ( drivePath, searchPattern );

The dialog box has the following message

"There is no disk in the drive. Please insert a disk into drive D:."

There are three buttions: Cancel, Try Again, and Continue.

Pressing continue causes the following exception.

Source: mscorlib
Exception Type: System.IO.IOException
Message: The device is not ready.
 
Calling SetErrorMode seems to do the trick.

public const uint SEM_FAILCRITICALERRORS = 0x0001;
public const uint SEM_NOGPFAULTERRORBOX = 0x0002;
public const uint SEM_NOALIGNMENTFAULTEXCEPT = 0x0004;
public const uint SEM_NOOPENFILEERRORBOX = 0x8000;

// Not sure about SetLastError=true
[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
public extern static int SetErrorMode(uint mode);
 
I was running on XP pro.

Imran Koradia said:
strange - I have framework v1.1. Are you running Windows 2000 or WindowsXP?
I didn't test it on WindowsXP but I sure didn't get the windows messagebox
on windows 2000.

Imran.

John R. Aldrin said:
The dialog is displayed before the exception is thrown.

I did some searching on Google and I saw some threads that said this was a
problem w/version 1.1 of .Net. Version 1.0 of .Net did not have this problem.

Imran Koradia said:
I didn't get the windows messagebox on windows 2000. Nevertheless, you could
try skipping the exception:

try {
string[] sfiles = System.IO.Directory.GetFiles(@"E:\", "*.txt");
}
catch(System.IO.IOException ex) {
if(ex.Message == "The device is not ready.\r\n") {
//skip this error..
}
}


hope that helps..
Imran.

Hi,

Windows displays a dialog box when I attempt to read files from a CD Drive
and there is not a CD loaded. Anyone know how to stop this dialog from
being
displayed?

Following is code used to read drive. drivePath is equal to @"d:\" and d
is
my CD rom drive.

Directory.GetFiles ( drivePath, searchPattern );

The dialog box has the following message

"There is no disk in the drive. Please insert a disk into drive D:."

There are three buttions: Cancel, Try Again, and Continue.

Pressing continue causes the following exception.

Source: mscorlib
Exception Type: System.IO.IOException
Message: The device is not ready.
 
Back
Top