3

To get the removable drives i have used GetDriveType ( ) function

Is it possible to check whether a drive is floppy drive or not ?

Please let me know your suggestions on this...

Thank you dor any help

user198725878
  • 6,266
  • 18
  • 77
  • 135
  • possible duplicate of [Programmatically differentiating between USB Floppy Drive and USB Flash Drive in Windows](http://stackoverflow.com/questions/1797128/programmatically-differentiating-between-usb-floppy-drive-and-usb-flash-drive-in) – MSalters Jul 01 '10 at 11:30

3 Answers3

4

Internally, Microsoft Windows holds named characteristics flags (defined in wdm.h) for every device. If the device which corresponds the drive letter has flag FILE_FLOPPY_DISKETTE, then the drive is a floppy drive:

//
// Define the various device characteristics flags (defined in wdm.h)
//
#define FILE_REMOVABLE_MEDIA                    0x00000001
#define FILE_READ_ONLY_DEVICE                   0x00000002
#define FILE_FLOPPY_DISKETTE                    0x00000004
#define FILE_WRITE_ONCE_MEDIA                   0x00000008
#define FILE_REMOTE_DEVICE                      0x00000010
#define FILE_DEVICE_IS_MOUNTED                  0x00000020
#define FILE_VIRTUAL_VOLUME                     0x00000040
#define FILE_AUTOGENERATED_DEVICE_NAME          0x00000080
#define FILE_DEVICE_SECURE_OPEN                 0x00000100
#define FILE_CHARACTERISTIC_PNP_DEVICE          0x00000800
#define FILE_CHARACTERISTIC_TS_DEVICE           0x00001000
#define FILE_CHARACTERISTIC_WEBDAV_DEVICE       0x00002000

To get characteristics flags of a drive you can use different API functions. I find as a most effective and simple way to use NtQueryVolumeInformationFile function from ntdll.dll. Under Get information about disk drives result on windows7 - 32 bit system you will find an example of usage of this API.

UPDATE: You can use NtQueryVolumeInformationFile function directly without previous calls of IOCTL_STORAGE_GET_DEVICE_NUMBER and IOCTL_STORAGE_QUERY_PROPERTY which was called in the example for another reasons.

UPDATED 2: By the way the usage of GetDriveType to test if a drive is removeable is not safe. I have many removable hardware where GetDriveType show the drive as non removeable, but characteristics flags has do has FILE_REMOVABLE_MEDIA bit set. Usage of SetupDiGetDeviceRegistryProperty with SPDRP_REMOVAL_POLICY is also safe. In the last case you should test for CM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVAL or CM_REMOVAL_POLICY_EXPECT_ORDERLY_REMOVAL like I do this in the example Get information about disk drives result on windows7 - 32 bit system.

Brogan
  • 708
  • 5
  • 13
Oleg
  • 220,925
  • 34
  • 403
  • 798
2

It's possible - have a look at the following Microsoft Knowledge Base Article.

humbagumba
  • 2,054
  • 15
  • 16
  • +1: I was just about to post the very same link ;) However, please note that this guaranteed only for Windows OSes up to Windows XP. – ereOn Jul 01 '10 at 09:07
-2

The best chance that I know of is to check if the drive letter is A: or B:. I haven't tried attaching three USB floppy drives to one PC so I don't know if a floppy might have a higher drive letter. Other quirks are possible too. But this test is nearly reliable enough for some purposes.

Windows programmer
  • 7,871
  • 1
  • 22
  • 23
  • 1
    This is just wrong. I've seen many computers where `A:` was mapped to a network drive or even a real physical hard-drive. – ereOn Jul 01 '10 at 09:03
  • This is bad advice - any type of drive can have any drive letter in Windows. – JBRWilkinson Jul 01 '10 at 09:18
  • JBRWilkinson, it looks like you're right sometimes. http://support.microsoft.com/kb/307844/en-us, "Drive letters A and B are reserved for floppy disk drives. However, if your computer does not have a floppy disk drive, you can assign these letters to removable drives." Oddly on my computers that don't have floppies Windows still reserved letters A and B for floppies, except when other quirks occured as mentioned in my posting. – Windows programmer Jul 01 '10 at 23:59