check floppy Drive

让人想犯罪 __ 提交于 2019-12-23 20:31:27

问题


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


回答1:


Internally Microsoft Windows hold so named characteristics flags (defined in wdm.h) for every device. If 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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/3156284/check-floppy-drive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!