在Windows中以USB编程方式区分USB软盘驱动器和USB闪存驱动器 [英] Programmatically differentiating between USB Floppy Drive and USB Flash Drive in Windows

查看:478
本文介绍了在Windows中以USB编程方式区分USB软盘驱动器和USB闪存驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows(XP-7)上,是否有一种可靠的方法在C ++中对USB软盘驱动器和USB闪存驱动器进行编程区分?

On Windows (XP-7), is there a reliable way of programatically differentiating between USB floppy drives and USB flash drives in C++?

使用WMI在新的 <$ c $检测到c> Win32_LogicalDisk 实例,然后使用LogicalDisk对象的DriveType属性计算出基本类型。这工作得很好,除了软盘驱动器和USB闪存驱动器都是DriveType DRIVE_REMOVABLE ,所以为了区分这些(软盘和闪存),我使用< a href =http://msdn.microsoft.com/en-us/library/aa510113.aspx =nofollow> IOCTL_STORAGE_GET_HOTPLUG_INFO 介面找出设备是否可热插拔,并且正在工作,这意味着它是一个闪存驱动器,而不是软盘。再次,我认为这是非常好的(如果一点效率低,使用WDK API和WMI获取信息)在内部软盘驱动器的情况下,但不幸的是USB软盘驱动器也是很多时间可热插拔,所以有没有明确的方法来区分闪存和USB软盘驱动器,我可以看到。我知道有属性可以工作,如检查其映射到保留的驱动器A:或B(编辑:只有相关,如果机器绝对有一个软盘驱动器 - 参见 MS-KB:如何在Windows XP中更改驱动器号分配)或查看说明,但我真的很喜欢一些更可靠的。

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. 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. 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. 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.

对长期的解释很抱歉,但只是想清楚!感谢

Sorry about the long explanation, but just wanted to be clear! Thanks

推荐答案

您尝试过Win32_LogicalDisk.MediaType吗?它有软盘的特定枚举。确保您在驱动器中没有磁盘时尝试。

Did you try Win32_LogicalDisk.MediaType? It has specific enumerations for floppy disks. Make sure you try it when there's no disk in the drive.

这篇关于在Windows中以USB编程方式区分USB软盘驱动器和USB闪存驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆