如何使用 C++ WinAPI 获取存储 USB 的名称?

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

我想要的细节喜欢这张图片中的"USB NAME"


得到字母"F"也很有用。
请注意,这些代码必须能够 运行 在 winxp 和更高版本上。
感谢您的帮助!

您可以使用 DeviceIOControlSetupDiGetDeviceInterfaceDetail

的组合

完整的源代码在 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不要尝试获取序列号,因为某些 USB 设备制造商不支持序列号)

其他可能性(更容易)是使用 GetDriveType()GetDisksProperty() 的组合源代码在 https://www.codeproject.com/Articles/6559/How-To-get-the-usbdisk-s-drive-letter-properly

一个非常简单的版本在

另一种可能性是 How to list physical disks? and GetLogicalDrives() for loop(使用 GetLogicalDrive(returns 一个 位掩码,必须将其转换为公共驱动器号A:, B: C:,...)) <- 这太复杂了

不在 C++ 中你可以使用 wmic 工具