I'd like to write a software that automatically copies some files onto a usb thumbdrive when it gets connected to the usb port. for this i would like to know:
how can I write a c++ application that gets notified when a usb thumbdrive gets connected?
is there any way to identify the usb thumbdrive, so that i can keep track off whether or not a new usb thumbdrive was inserted already?
我认为您可以使用WM_DEVICECHANGE窗口消息在设备插入或从系统中删除时收到通知,这里有一个链接供进一步阅读http://msdn.microsoft.com/en-us/library/windows/desktop/ aa363480%28V = vs.85%29.aspx
Krister's answer covers the basics. What he doesn't metion is how to do (2), idenifying it. You're looking for the DBT_DEVTYP_DEVICEINTERFACE
arrival event. This event contains a dbcc_name
, which is identifies the exact device. (Provided that the device adheres to the USB specification and has a unique serial number; don't expect cheap Chinese devices to.)
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.