How to get the Drive Letter for the DevicePath

后端 未结 2 1551
无人共我
无人共我 2020-12-18 09:04

I am using Win32 API.

Really i do not understand how to get the drive letter for DevicePath of a USB stick .

can you pls explain it to me

( what i ha

相关标签:
2条回答
  • 2020-12-18 09:19

    The link I provided in your other question gives you all the information you need to do this. In semi-pseudocode:

    DiskDevice = CreateFile(DiskDevicePath);
    DiskDeviceNumber = DeviceIoControl(DiskDevice, IOCTL_STORAGE_GET_DEVICE_NUMBER);
    for each VolumeDevicePath in GetLogicalDriveStrings
        VolumeDevice = CreateFile(VolumeDevicePath);
        VolumeDeviceNumber = DeviceIoControl(VolumeDevice, IOCTL_STORAGE_GET_DEVICE_NUMBER);
        if(VolumeDeviceNumber == DiskDeviceNumber)
            // volume (i.e. "G:") corresponding to VolumeDevicePath resides on disk (i.e. "XYZ USB Storage Device") corresponding to DiskDevicePath
    

    I'm not 100% sure (it's been a while), but I think that the Disk device (GUID_DEVINTERFACE_DISK) is a child of the USB device (GUID_DEVINTERFACE_USB_DEVICE). In any event, I think DiskDevicePath needs to be the path of the Disk device (not the USB device).

    0 讨论(0)
  • 2020-12-18 09:34

    Take a look at this, maybe it'll help (I don't think there's an easy way to do it ...)

    http://msdn.microsoft.com/en-us/library/cc542456(VS.85).aspx

    0 讨论(0)
提交回复
热议问题