以编程方式弹出USB设备正在使用中 [英] Programmatically Eject USB Device while it is in use

查看:262
本文介绍了以编程方式弹出USB设备正在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使正在使用,我如何以编程方式弹出USB设备?



场景:



连接到系统的USB设备。



我们通过RegisterDeviceNotification获取WM_DEVICECHANGE消息,我们可以通过它来处理DBT_DEVICEARRIVAL,DBT_DEVICEQUERYREMOVE等事件。



现在,如果设备正在使用中,如果我们要将它从资源管理器中弹出,则会提示弹出USB大容量存储设备问题此设备当前正在使用中。关闭可能正在使用该设备的所有程序或窗口,然后再试一次。

问题:1:如何在没有任何提示的情况下弹出USB?



问题:2:当用户按下从资源管理器中弹出USB设备时,我们如何收到通知?



提前致谢: )

解决方案

我会说这是一个坏主意,它会以泪流满面。如果你编写可能导致数据丢失的代码,那么很有可能它会回来咬你的屁股,使用美国主义。



显然,这只是我的意见,但是......好吧,这是有道理的我

How can i programmatically eject USB Device even if it is in use?

Scenarios:

USB device attached to the system.

We get WM_DEVICECHANGE message by "RegisterDeviceNotification" through which we can handle events like DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE etc.

Now if the device is in use, if we want to eject it from explorer, it prompts as "Problem Ejecting USB Mass Storage Device "This device is currently in use. Close any programs or windows that might be using the device, and then try again."
Question: 1: How can we eject USB without any prompt while it is in use?

Question: 2: How can we get notification when the user press eject from explorer for USB device?

Thanks in advance :)

解决方案

I would say that this is a bad idea, and it will end in tears. If you write code which could cause loss of data, the chances are that it will come back and bite you in the ass, to use the Americanism.

Obviously, this is just my opinion, but... well, it makes sense to me.


这篇关于以编程方式弹出USB设备正在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆