WiXXeY
WiXXeY

Reputation: 1001

Ejecting a USB Drive

I am following the CodeProject Tutorial to remove a USB drive in C#. the issue I am facing is the USB Pen Drive eject successfully but doesn't works on a portable hard drive. code is given below

int r = CM_Request_Device_Eject_NoUi(DevInstParent, IntPtr.Zero, null, 0, 0);
LogFile.Err("Eject Return value - " + r);

When a USB pen drive is forced to eject the integer r returns 0 and eject command is successful, but when a portable drive is forced to eject, it returns 23.

Upvotes: 2

Views: 2386

Answers (1)

Troy Jennings
Troy Jennings

Reputation: 432

According to cfgmgr32.h, 23 (0x17) is CR_REMOVE_VETOED, suggesting that the OS is overruling your attempt to remove the drive. Looking at the code you've linked, CM_Request_Device_Eject_NoUi is just calling CM_Request_Device_Eject without using an out parameter for pVetoType, so your Veto Reason is being discarded without informing you.

Adjust your code to show you the value of pVetoType. You will almost certainly need to find a copy of cfgmgr32.h's source code to know what the returned value signifies. That information will be necessary for any furthur debugging.

Upvotes: 1

Related Questions