开发者

check floppy Drive

To开发者_如何学C 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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜