如果检测到新驱动器,则发生事件 [英] If new drive detected.. an event happens

查看:64
本文介绍了如果检测到新驱动器,则发生事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个应用程序,如果Windows操作系统检测到新驱动器,则会触发该应用程序上的事件.

尽管我打算做的是检查应用程序

有没有建议?

I am trying to create an application where, if new drive has been detected by the windows operating system, an event on the application is triggered.

Although what i was planning to do is the application to check for new drives in a given time interval but seems like that is not the appropriate thing to do.

Any suggestions?

推荐答案

尝试响应 WM_DEVICECHANGE [ DBT_DEVICEARRIVAL [
Try responding to the WM_DEVICECHANGE[^] window message. A WParam value of DBT_DEVICEARRIVAL[^] should indicate a new cd/usb drive.

Will probably only work if you have auto insert notification turned on for the drive.




可以从System.Management ManagementEventWatcher中使用WqlEventQuery类.
WqlEventQuery对象的USB驱动器将具有Condition = @"TargetInstance ISA""Win32_USBControllerdevice"",而其他类型的驱动器将具有类似的条件.
订阅ManagementEventWatcher对象的EventArrived事件.
You can use from System.Management ManagementEventWatcher, WqlEventQuery classes.
WqlEventQuery object will have Condition = @"TargetInstance ISA ""Win32_USBControllerdevice""" for USB drives and similar for other types of drives.
Subscribe to EventArrived event of ManagementEventWatcher object.


这篇关于如果检测到新驱动器,则发生事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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