How to programmatically get the Device Instance ID (unique ID) of a USB mass storage device that a user just plugged in?
Getting USB Storage Device Instance ID (unique ID) programmatically
4.2k Views Asked by Navaneeth At
2
There are 2 best solutions below
2

I think you can do it using WMI. Look at the Win32_LogicalDiskToPartition
class to get a list of all disk names and then use those names to query the class Win32_DiskDrive
and it's PNPDeviceID
property.
Actually, look here for better instructions and a nice class that does it for you.
Catch WM_DEVICECHANGE from any window handle by registering for device change notifications. As such:
The lParam of the WM_DEVICECHANGE can be cast to DBT_DEVTYP_DEVICEINTERFACE. Note - when plug in a device you may get multiple WM_DEVICECHANGE notifications. Just filter on the arrival event and ignore duplicates.