1

The detail I want likes "USB NAME" in this image enter image description here


Getting the letter "F" is also usefull.
Note that these code must able to run on winxp and newer.
Thanks for your help!

MD XF
  • 7,860
  • 7
  • 40
  • 71
  • 1
    from your question unclear what you have on input, and what need got on output. for example volume label ? you can use [`GetVolumeInformation`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx) for this. but are you have `lpRootPathName` on input ? unclear – RbMm Feb 18 '17 at 02:42

1 Answers1

-2

you can use a combination of DeviceIOControl and SetupDiGetDeviceInterfaceDetail

full source code is on Get USB disk drive letter by device path or handle

( https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/a87c4cc3-bfc1-4664-8317-af30f03a715e/get-usb-drive-details?forum=wdk do not try to get a serial number because some manufacturers of USB devices di not support serial numbers)

other possiblity (easier) is to use combination of GetDriveType() and GetDisksProperty() source code is on https://www.codeproject.com/Articles/6559/How-To-get-the-usbdisk-s-drive-letter-properly

a very easy version is in How to retrieve removable storage drive letter using C/C++

yet another possibility is on How to list physical disks? and GetLogicalDrives() for loop (uses GetLogicalDrive (returns a bitmask that has to be translated to the common drive letters A:, B: C:,...)) <- this is too complicated

not in C++ you could use wmic tool

Community
  • 1
  • 1
ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Those look like helpful links, but the information you added in your answer is highly suspect? "USB standard does not support serial number" Who told you that? The USB standard does provide for a serial number, it's some device manufacturers that didn't follow the standard and either left a serial out or used the same one on every device. "this is too complicated" It's much less complicated than using `DeviceIOControl` and `SetupDi`* functions. – Ben Voigt Feb 18 '17 at 19:31
  • Thanks @raft htp, that seems very usefull, I 'll up my solution for others after done! – Thanh Tùng Vũ Feb 20 '17 at 00:43
  • I need this also. I check all yours links and i couldn't find how to get usb drive letter (e.g. F:). I can get VID and PID wich is important for me but also i need usb letter for that device so i can open files from it. – Milan Kocic Nov 10 '17 at 15:10
  • you have to translate the bitmask returned by `GetLogicalDrives()` to the drive letter, this is in https://msdn.microsoft.com/de-de/library/windows/desktop/aa364972(v=vs.85).aspx – ralf htp Nov 12 '17 at 09:00