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

发布于 2024-08-13 06:24:54 字数 925 浏览 14 评论 0 原文

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

目前,我正在使用 WMI 在新 Win32_LogicalDisk 实例被检测到,然后使用 LogicalDisk 对象的 DriveType 属性来找出基本类型。这工作得很好,除了软盘驱动器和 USB 闪存驱动器都是 DriveType DRIVE_REMOVABLE,因此为了区分这些驱动器(软盘与闪存),我使用 IOCTL_STORAGE_GET_HOTPLUG_INFO 接口,用于确定设备是否可热插拔以及是否正常工作原则上这意味着它是闪存驱动器而不是软盘。再说一次,我认为在内部软盘驱动器的情况下,这工作得很好(如果有点低效,使用 WDK API 和 WMI 来获取信息),但不幸的是 USB 软盘驱动器很多时候也是可热插拔的,所以有据我所知,没有明确的方法来区分闪存驱动器和 USB 软盘驱动器。我知道有些属性可能起作用,例如检查它是否映射到保留驱动器A:或B(编辑:仅当机器确实有软盘驱动器时才相关 - 请参阅MS-KB:如何更改 Windows XP 中的驱动器盘符分配),或查看说明,但我真的很想喜欢更可靠一点的东西。

抱歉解释太长,但只是想弄清楚!谢谢

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

埋情葬爱 2024-08-20 06:24:54

您尝试过 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.

︶ ̄淡然 2024-08-20 06:24:54

在 USB 级别,无法区分传统的 Key 型磁盘和 USB 软盘。这意味着 Windows 本身无法可靠地分辨什么是什么。

您可以收集一些提示:
软盘应该:
一个。具有海量存储协议CBI/CB
b. SCSI UFI

但是,在 USB 设备的世界中,每个人都可以为所欲为。唯一的测试是:“它在 Windows 上运行吗”。 Windows 只是检查大小,如果它是具有可移动介质集且具有传统软盘大小的 USB 设备,它会认为它是软盘。

不能说“真正的”软盘,但对于连接的 USB,没有明确的方法。

On the USB level, there is no way to differentiate between a conventional Disk on Key and a USB-Floppy. Which means windows itself, cannot tell reliably what is what.

There are a few hints that you can gather:
Floppies should:
a. Have mass-storage protocol CBI/CB
b. SCSI UFI

BUT, in the world of USB devices, everyone does whatever they want. The only test is: "Does it work on 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.

Can't say about "real" floppy, but with the USB attached, there is no definite way.

黎歌 2024-08-20 06:24:54

您可以使用“大小”属性(USB > 1.4MB),但短期内不太可能遇到 1.4MB 闪存驱动器。

You can use the Size attribute (USB > 1.4MB), it's not like there is any chance of meeting 1.4MB flash drive any time soon.

迷荒 2024-08-20 06:24:54

要检查的明显属性是IOCTL_DISK_GET_DRIVE_GEOMETRY。这将为您提供(除其他外)MEDIA_TYPE。除RemovableMediaFixedMedia 之外的任何内容都是软盘。

The obvious property to check would be IOCTL_DISK_GET_DRIVE_GEOMETRY. This gets you (amongst other things) a MEDIA_TYPE. Anything but RemovableMedia and FixedMedia is a floppy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文