I wonder if there is an API to distinguish floppy and flash disk in windows, C++ And is it possible to link a flash disk to A:\? Many Thanks!
3 Answers
First, you need to get the drive's type (GetDriveTypeA). If the result is equal to DRIVE_REMOVABLE, the letter drive will point either to a floppy of a removable flash drive (or maybe other type of removable disk). If the result is not DRIVE_REMOVABLE, there is no chance that this is a removable flash drive. However, beware from the point of view Window has, there is little difference between an external USB harddrive and a removable flash disk (I think the only difference is that a removable flash disk does not have a partition table, so it will have only one partition - though I'm not very sure).
Anyway, for DRIVE_REMOVABLE type, you need to query for more advanced properties of the device. In order to do this, first you need to open the physical device with somethink like this:
hDevice = CreateFileA("\\\\?\\X:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL)
If the open succeeds, you need to issue a DeviceIoControl command to this device:
STORAGE_PROPERTY_QUERY Query;
Query.PropertyId = StorageDeviceProperty;
Query.QueryType = PropertyStandardQuery;
bResult = DeviceIoControl(
hDevice, // device handle
IOCTL_STORAGE_QUERY_PROPERTY, // info of device property
&Query, sizeof(STORAGE_PROPERTY_QUERY), // input data buffer
pDevDesc, pDevDesc->Size, // output data buffer
&dwOutBytes, // out's length
(LPOVERLAPPED)NULL
);
If pDevDesc->BusType == BusTypeUsb, then X: points to a removable flash drive. The code works, however you need to read the documentation for DeviceIoControl in order to setup the pDevDesc parameter. If you have problems with it, I can give you the whole code.

- 2,977
- 2
- 30
- 29
-
Presumably for a USB floppy drive `pDevDesc->BusType == BusTypeUsb` too. – MSalters Feb 02 '10 at 08:43
-
You can change the letters assigned to your drives somewhere in System Control, so the flash disk can be A:.
Use the OS API to query eg. the size of the disk, that should be enough to distinguish floppy and flash disk.

- 1,935
- 11
- 9
It is possible to link a flash disk to A:, but only if you have no floppy drives.
See Defining an MS-DOS Device Name for information about how to do this in a program.
You can determine whether a drive letter maps to a floppy device by using QueryDosDevice on the drive letter. Floppy drives will return "\Device\Floppy0" or "\Device\Floppy1"

- 33,512
- 4
- 61
- 92
-
Note that the `\Device\Floppy
` names are not (always) used for USB floppy drives. – MSalters Feb 01 '10 at 11:44 -
-