windows - Given a volume (eg Z:), how to tell if that volume is on a device that is "removable"? -


After

I want to know whether the disk that remains on any volume is removable (CM_DEVCAP_REMOVABLE). Looking for signals for Win32

Explain: .. What I'm trying to find out is that the disk that is on the volume of the volume that is external to the computer is connected to a port (USB for example)

You can open volume and issue IOCTL_STORAGE_QUERY_PROPERTY; It gives a STORAGE_DEVICE_DESCRIPTOR which is a RemovableMedia property. I believe this is similar to CM_DEVCAP_REMOVABLE (% No 100 is sure). At least this report "fix" USB as a removable flash drive

  handle HFile = CreateFile ( "\\\\ \\ Z :."., FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, Zero, OPEN_EXISTING, 0, zero); If (hFile! = INVALID_HANDLE_VALUE) {STORAGE_PROPERTY_QUERY storage property query; Storageproduct.productID = storagedeviceparty; StoragePropertyQuery.QueryType = PropertyStandardQuery; Byte buffer [1024]; If (DeviceIoControl (HFile, IOCTL_STORAGE_QUERY_PROPERTY, and SotragePropertyQuery, size (STORAGE_PROPERTY_QUERY), buffer 1024, and bytes return NULL)) {PSTORAGE_DEVICE_DESCRIPTOR Sngrhndiwais descriptor = (PSTORAGE_DEVICE_DESCRIPTOR) buffer; If (Storage Division descriptor-> Removable media) {printf ("Z: IS is removable \ n"); } Other {printf ("Z: can not be removed \ n"); }} CloseHandle (hFile); HFile = INVALID_HANDLE_VALUE; }  

Comments