简体   繁体   English

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

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

The detail I want likes "USB NAME" in this image 我想要的细节喜欢这张图中的“ USB NAME” 在此处输入图片说明


Getting the letter "F" is also usefull. 获取字母“ F”也很有用。
Note that these code must able to run on winxp and newer. 请注意,这些代码必须能够在winxp及更高版本上运行。
Thanks for your help! 谢谢你的帮助!

you can use a combination of DeviceIOControl and SetupDiGetDeviceInterfaceDetail 您可以结合使用DeviceIOControlSetupDiGetDeviceInterfaceDetail

full source code is on Get USB disk drive letter by device path or handle 完整的源代码位于按设备路径或句柄获取USB磁盘驱动器号

( 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) https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/a87c4cc3-bfc1-4664-8317-af30f03a715e/get-usb-drive-details?forum=wdk不要尝试获取序列号因为某些USB设备制造商不支持序列号)

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 其他可能性(更简便)是结合使用GetDriveType()GetDisksProperty()源代码位于https://www.codeproject.com/Articles/6559/How-To-get-the-usbdisk-s-drive-letter -适当地

a very easy version is in How to retrieve removable storage drive letter using C/C++ 一个非常简单的版本是如何使用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 GetLogicalDrives()进行循环 (使用GetLogicalDrive (返回必须转换为通用驱动器字母A:, B: C:,...位掩码 ))<-这太复杂了

not in C++ you could use wmic tool 不在C ++中,您可以使用wmic工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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