How to eject a USB removable disk/volume, similar to the “Eject” function in Windows Explorer?

后端 未结 2 1487
野性不改
野性不改 2020-12-31 05:56

Do you know what is the API, or sequence of API calls that windows uses to accomplish the \"Eject\" function which is available on the shell context menu for removable volum

相关标签:
2条回答
  • 2020-12-31 06:24

    Eventually, I found out where I was making a mistake with approach #2.

    It turns out that for some reason I was not setting the desired access correctly when opening the handle to the volume using CreateFile.

    The correct access mode is GENERIC_READ | GENERIC_WRITE and I was passing 0. After correcting my error I was able to successfully eject the device using DeviceIoControl - IOCTL_STORAGE_EJECT_MEDIA, as well as with method #1, using CM_Request_Device_Eject.

    Finally, it turns out that method #2 is indeed the method used by the shell context menu's "Eject" function. Using this method the device reacts correctly.

    0 讨论(0)
  • 2020-12-31 06:36

    I came here accidentally while doing a search on "CM_Request_Device_Eject", and saw that it was similar to a solution I'd recently done by pulling together similar pieces of a solution. Forgive the late answer.

    I've summarized the steps I've done for this on my project in this SO answer.

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