简体   繁体   English

以编程方式区分Windows中的USB软盘驱动器和USB闪存驱动器

[英]Programmatically differentiating between USB Floppy Drive and USB Flash Drive in Windows

On Windows (XP-7), is there a reliable way of programatically differentiating between USB floppy drives and USB flash drives in C++? 在Windows(XP-7)上,是否有一种可靠的方式在C ++中以编程方式区分USB软盘驱动器和USB闪存驱动器?

At the moment, I'm using WMI to get updates when new Win32_LogicalDisk instances are detected, and then using the DriveType attribute of the LogicalDisk object to figure out a basic type. 目前,我正在使用WMI在检测到新的Win32_LogicalDisk实例时获取更新,然后使用LogicalDisk对象的DriveType属性来确定基本类型。 This works quite well, except that floppy drives and USB flash drives are both of DriveType DRIVE_REMOVABLE , so to differentiate between those (floppy vs. flash), I'm using the IOCTL_STORAGE_GET_HOTPLUG_INFO interface to figure out if the device is hotpluggable, and was working on the principal that that meant it was a flash drive and not a floppy. 这很好用,除了软盘驱动器和USB闪存驱动器都是DriveType DRIVE_REMOVABLE ,所以为了区分它们(软盘和闪存),我正在使用IOCTL_STORAGE_GET_HOTPLUG_INFO接口来判断设备是否可以热插拔,并且正在工作在校长,这意味着它是一个闪存驱动器,而不是软盘。 Again, I think this works quite well (if a little inefficient, using both the WDK API and WMI to get info ) in the case of internal floppy drives, but unfortunately USB Floppy drives are also hotpluggable a lot of the time, so there is no clear way to differentiate between flash and USB floppy drives, that I can see. 再说一遍,我认为在内置软盘驱动器的情况下,这种方法效果很好(如果使用WDK API和WMI来获取信息的效率有点低),但不幸的是USB软盘驱动器在很多时候也是热插拔的,所以有没有明确的方法来区分闪存和USB软盘驱动器,我可以看到。 I know there are properties that may work, like checking if its mapped to the reserved drives A: or B (edit: only relevant if the machine definitely has a floppy drive - see MS-KB: How to change drive letter assignments in Windows XP ), or looking at the description, but I'd really like something a bit more reliable. 我知道有些属性可以工作,比如检查它是否映射到保留的驱动器A:或B(编辑:仅当机器肯定有软盘驱动器时才相关 - 请参阅MS-KB:如何更改Windows XP中的驱动器号分配 ),或者看一下描述,但我真的想要一些更可靠的东西。

Sorry about the long explanation, but just wanted to be clear! 很抱歉很长的解释,但只是想明确! Thanks 谢谢

Did you try Win32_LogicalDisk.MediaType? 你试过Win32_LogicalDisk.MediaType吗? It has specific enumerations for floppy disks. 它具有特定的软盘枚举。 Make sure you try it when there's no disk in the drive. 确保在驱动器中没有磁盘时尝试使用它。

On the USB level, there is no way to differentiate between a conventional Disk on Key and a USB-Floppy. 在USB级别上,无法区分传统的磁盘密钥和USB软盘。 Which means windows itself, cannot tell reliably what is what. 这意味着Windows本身,无法可靠地分辨出什么是什么。

There are a few hints that you can gather: Floppies should: a. 你可以收集一些提示:Floppies应该:a。 Have mass-storage protocol CBI/CB b. 有大容量存储协议CBI / CB b。 SCSI UFI SCSI UFI

BUT, in the world of USB devices, everyone does whatever they want. 但是,在USB设备的世界里,每个人都做他们想做的事。 The only test is: "Does it work on windows". 唯一的测试是:“它是否适用于Windows”。 And Windows just checks the size, if its a USB device with removable-media set and with conventional floppy sizes, it will consider it to be a floppy. Windows只是检查大小,如果它是带有可移动媒体设置的USB设备和传统的软盘大小,它会认为它是一张软盘。

Can't say about "real" floppy, but with the USB attached, there is no definite way. 不能说“真正的”软盘,但随着USB附加,没有明确的方法。

你可以使用Size属性(USB> 1.4MB),它不会有任何机会在短时间内满足1.4MB的闪存驱动器。

The obvious property to check would be IOCTL_DISK_GET_DRIVE_GEOMETRY . 要检查的明显属性是IOCTL_DISK_GET_DRIVE_GEOMETRY This gets you (amongst other things) a MEDIA_TYPE . 这会让你(除其他外)成为一个MEDIA_TYPE Anything but RemovableMedia and FixedMedia is a floppy. 除了RemovableMediaFixedMedia任何东西都是软盘。

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

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