简体   繁体   中英

Windows - How do I disable the “Wrong Volume” error message

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

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.

I suggest you properly disconnect your hardware using the icon in the windows system tray so that it's not being accessed when you pull it out of the drive. Or at least exit your ap first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM