检查软盘驱动器
为了获取可移动驱动器,我使用了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在内部,Microsoft Windows 为每个设备保存命名的特征标志(在 wdm.h 中定义)。如果对应驱动器盘符的设备具有标志
FILE_FLOPPY_DISKETTE
,则该驱动器是软盘驱动器:要获取驱动器的特征标志,您可以使用不同的API函数。我发现使用 ntdll.dll 中的
NtQueryVolumeInformationFile
函数是最有效、最简单的方法。在 获取有关 Windows7 - 32 位系统上磁盘驱动器结果的信息,您将找到使用此 API 的示例。更新:您可以直接使用
NtQueryVolumeInformationFile
函数,而无需先前调用示例中调用的IOCTL_STORAGE_GET_DEVICE_NUMBER
和IOCTL_STORAGE_QUERY_PROPERTY
另一个原因。更新2:顺便说一句,使用
GetDriveType
来测试驱动器是否可移除并不安全。我有许多可移动硬件,其中GetDriveType
将驱动器显示为不可移动,但特征标志确实设置了FILE_REMOVABLE_MEDIA
位。将SetupDiGetDeviceRegistryProperty
与SPDRP_REMOVAL_POLICY
一起使用也是安全的。在最后一种情况下,您应该测试CM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVAL
或CM_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: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 ofIOCTL_STORAGE_GET_DEVICE_NUMBER
andIOCTL_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 whereGetDriveType
show the drive as non removeable, but characteristics flags has do hasFILE_REMOVABLE_MEDIA
bit set. Usage ofSetupDiGetDeviceRegistryProperty
withSPDRP_REMOVAL_POLICY
is also safe. In the last case you should test forCM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVAL
orCM_REMOVAL_POLICY_EXPECT_ORDERLY_REMOVAL
like I do this in the example Get information about disk drives result on windows7 - 32 bit system.这是可能的 - 请查看以下Microsoft 知识库文章。
It's possible - have a look at the following Microsoft Knowledge Base Article.
据我所知,最好的办法是检查驱动器号是 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.