I'm working in a small tool to log activity in USB devices.
My tool works as a windows service catching all the device events, basically I'm starting to monitor the USB device as soon I catch a DBT_DEVICEARRIVAL
event. After this, I need to stop the monitor as soon I get the DBT_DEVICEQUERYREMOVE
(otherwise my service will deny the device to be safe ejected). The problem is that the tool should be able to monitor several number of devices, so I need to be able to determine which device is the user trying to eject.
I found out that the DBT_DEVICEQUERYREMOVE
event carries a DEV_BROADCAST_HANDLE
structure. I'm trying to extract some useful information from this structure that can allow me to identify which device is being ejected. I found out that there is a handle to the device, I tried to extract the drive letter using the system function GetFinalPathNameByHandle
but is not working properly (returning empty value).
Any idea how can I do this?
Thank you very much!