determine if drive is removable (flash or HDD) knowing only the drive letter

一曲冷凌霜 提交于 2019-12-06 17:40:26

You should read the doco more closely. While a Flash drive is considered a fixed device, there's a note in that linked page:

To determine whether a drive is a USB-type drive, call SetupDiGetDeviceRegistryProperty and specify the SPDRP_REMOVAL_POLICY property.

The process seems a little messy if all you start with is the path but you can start reading the doco here. It looks like you may need to enumerate the devices until you find one matching your drive.

To avoid doing this to all your requests, I would do a two-stage check. If your current method says it's not fixed, treat it as non-local.

If it says it is fixed, then you can enumerate the devices using my suggested method to be certain.

Alternatively, you can enumerate all fixed non-USB drives the first time you need to, and then just cache the information. I'm pretty certain that the list of these drives won't change while the system is running - drives that get added and deleted are, by definition, removable.

You can try using DeviceIoControl and query for the BusType = BusTypeUsb by passing IOCTL_STORAGE_QUERY_PROPERTY as its second parameter. Read Determining USB by Thomas Lee at the bottom of page.

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