Find USB drive letter from VID/PID (Needed for XP and higher)

前端 未结 3 1955
逝去的感伤
逝去的感伤 2021-02-01 21:21

So I thought I would include the final answer here so you don\'t have to make sense of this post. Big thanks to Simon Mourier for taking the time to figure this one out.

3条回答
  •  鱼传尺愫
    2021-02-01 22:22

    There's an ancient Win32 API for device enumeration, it used to be part of the installer API but has fallen into disuse - I'm only aware of its existence, notsomuch its usage, but hopefully it'll be helpful:

    http://msdn.microsoft.com/en-us/library/windows/hardware/ff551015(v=vs.85).aspx

    The SP_DEVICE_INTERFACE_DETAIL structure is your end-goal: it has the actual device path. The path to get there, however... It'd all be PInvoke, and fairly nasty looking from the signatures, but here are some references:

    The PInvoke signatures:

    http://pinvoke.net/default.aspx/setupapi/SetupDiGetClassDevs.html http://pinvoke.net/default.aspx/setupapi/SetupDiEnumDeviceInterfaces.html http://pinvoke.net/default.aspx/setupapi/SetupDiGetDeviceInterfaceDetail.html

    The structure mappings:

    http://pinvoke.net/default.aspx/Structures/SP_DEVICE_INTERFACE_DATA.html http://pinvoke.net/default.aspx/Structures/SP_DEVICE_INTERFACE_DETAIL_DATA.html

    Ooh, I found some example usage (in C++, but fairly translatable):

    http://oroboro.com/usb-serial-number/

提交回复
热议问题