English 中文(简体)
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++?

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

最佳回答

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.

问题回答

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.

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.

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签