检查软盘驱动器

发布于 2024-09-08 10:41:41 字数 124 浏览 4 评论 0原文

为了获取可移动驱动器,我使用了 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...

Thank you dor any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

﹏半生如梦愿梦如真 2024-09-15 10:41:41

在内部,Microsoft Windows 为每个设备保存命名的特征标志(在 wdm.h 中定义)。如果对应驱动器盘符的设备具有标志FILE_FLOPPY_DISKETTE,则该驱动器是软盘驱动器:

//
// 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函数。我发现使用 ntdll.dll 中的 NtQueryVolumeInformationFile 函数是最有效、最简单的方法。在 获取有关 Windows7 - 32 位系统上磁盘驱动器结果的信息,您将找到使用此 API 的示例。

更新:您可以直接使用NtQueryVolumeInformationFile函数,而无需先前调用示例中调用的IOCTL_STORAGE_GET_DEVICE_NUMBERIOCTL_STORAGE_QUERY_PROPERTY另一个原因。

更新2:顺便说一句,使用GetDriveType来测试驱动器是否可移除并不安全。我有许多可移动硬件,其中 GetDriveType 将驱动器显示为不可移动,但特征标志确实设置了 FILE_REMOVABLE_MEDIA 位。将 SetupDiGetDeviceRegistryPropertySPDRP_REMOVAL_POLICY 一起使用也是安全的。在最后一种情况下,您应该测试 CM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVALCM_REMOVAL_POLICY_EXPECT_ORDERLY_REMOVAL 就像我在示例中所做的那样 获取有关 Windows7 - 32 位系统上磁盘驱动器结果的信息

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.

梦幻的味道 2024-09-15 10:41:41

这是可能的 - 请查看以下Microsoft 知识库文章

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

孤蝉 2024-09-15 10:41:41

据我所知,最好的办法是检查驱动器号是 A: 还是 B:。我还没有尝试将三个 USB 软盘驱动器连接到一台 PC,因此我不知道软盘是否可能具有更高的驱动器号。其他怪癖也是可能的。但对于某些目的来说,这个测试几乎足够可靠。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文