Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows - How do I disable the "Wrong Volume" error message

Tags:

c++

windows

My application is reading/writing data to a removable media (USB DOK) in the background. The problem is that when the USB is removed while the app is working, the computer pops up an error message:

Wrong Volume

The wrong volume is in the drive. Please insert volume into drive E:.

Cancel Try Again Continue

This happens during operations such as GetFileSize, ReadFile. Obviously, since the app is supposed to work in the background, I would like to suppress those messages and fail silently.

BTW - It seems that the process giving those message is not my process, but CSRSS.EXE (although the cause is definitely the operation from my process).

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

Thanks

like image 334
OSH Avatar asked Oct 24 '22 12:10

OSH


1 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 fails to find a file. Instead, the error is returned to the calling process.

like image 186
rodrigo Avatar answered Oct 27 '22 09:10

rodrigo