检查软盘驱动器 [英] check floppy Drive
问题描述
要得到我已经使用的 GetDriveType ()函数
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...
谢谢dor任何帮助
推荐答案
内部Microsoft Windows在每个设备上保存这样命名的特性标志(在wdm.h中定义)。如果对应驱动器盘符的设备标志 FILE_FLOPPY_DISKETTE
,则驱动器是一个软盘驱动器:
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
要获取驱动器的特征标志,可以使用不同的API函数。我发现作为一个最有效和简单的方法使用 NtQueryVolumeInformationFile
函数从ntdll.dll。在 http://stackoverflow.com/questions/3098696/how-to-get-the-vid-pid-and-drive-letter-for-all-the-usb-mass-storage-devices -plug / 3100268#3100268 您会发现此API使用的示例。
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 http://stackoverflow.com/questions/3098696/how-to-get-the-vid-pid-and-drive-letter-for-all-the-usb-mass-storage-devices-plug/3100268#3100268 you will find an example of usage of this API.
更新:您可以使用 NtQueryVolumeInformationFile
功能的情况下直接 IOCTL_STORAGE_GET_DEVICE_NUMBER
和 IOCTL_STORAGE_QUERY_PROPERTY
以前的电话这是所谓的
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:按照 GetDriveType
来测试驱动器是否可移动不安全。我有许多可移动的硬件,其中 GetDriveType
显示驱动器作为非可移动,但特征标志有做了 FILE_REMOVABLE_MEDIA
位置。使用 SetupDiGetDeviceRegistryProperty
与 SPDRP_REMOVAL_POLICY
也是安全的。在最后一种情况下,你应该测试 CM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVAL
或 CM_REMOVAL_POLICY_EXPECT_ORDERLY_REMOVAL
像我一样用这个例子的 http://stackoverflow.com/questions/3098696/how-to-get-the-vid-p-and-drive-letter-for-all-the-usb-mass-storage-devices-plug/3100268#3100268 。
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 http://stackoverflow.com/questions/3098696/how-to-get-the-vid-pid-and-drive-letter-for-all-the-usb-mass-storage-devices-plug/3100268#3100268.
这篇关于检查软盘驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!