简体   繁体   English

Windows - 如何禁用“错误卷”错误消息

[英]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. 我的应用程序是在后台读/写数据到可移动媒体(USB DOK)。 The problem is that when the USB is removed while the app is working, the computer pops up an error message: 问题是当应用程序运行时删除USB时,计算机会弹出一条错误消息:

Wrong Volume 错误的卷

The wrong volume is in the drive. 驱动器中的卷错误。 Please insert volume into drive E:. 请将音量插入驱动器E:。

Cancel Try Again Continue 取消再试一次继续

This happens during operations such as GetFileSize, ReadFile. 这在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). 顺便说一句 - 似乎提供这些消息的进程不是我的进程,而是CSRSS.EXE(虽然原因绝对是我的进程中的操作)。

One direction I am considering is switching to NtQueryInformationFile, NtReadFile, etc., but I'd rather not... 我正在考虑的一个方向是切换到NtQueryInformationFile,NtReadFile等,但我宁愿不...

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. 我建议您使用Windows系统托盘中的图标正确断开硬件连接,以便在将其从驱动器中拉出时不会被访问。 Or at least exit your ap first. 或者至少先退出你的ap。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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