简体   繁体   中英

How can I get the name of the storage USB with C++ WinAPI?

The detail I want likes "USB NAME" in this image 在此处输入图片说明


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

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM