Windows - How to disable the "Wrong Volume" error message

My application is reading / writing data to removable media (USB DOK) in the background. The problem is that when you remove the USB while the application is running, the computer displays an error message:

Invalid volume

The wrong volume is in the drive. Insert the volume into drive E :.

Cancel attempt to continue again

This happens during operations such as GetFileSize, ReadFile. Obviously, since the application should run in the background, I would like to suppress these messages and worked silently.

BTW. It seems that the process sending these messages is not my process, but CSRSS.EXE (although the reason, of course, is the operation of my process).

One direction I'm considering is switching to NtQueryInformationFile, NtReadFile, etc., but I would rather not ...

thank

+5
source share
2 answers

Try calling:

SetErrorMode(SEM_NOOPENFILEERRORBOX);

At the beginning of your main function.

From the documentation :

The system does not display a message box when it cannot find the file. Instead, an error is returned to the calling process.

+2
source

I suggest that you properly disconnect your equipment using the icon in the Windows system tray so that it is not accessible when you pull it out of the drive. Or at least exit your application first.

+1
source

All Articles