usbeject
usbeject copied to clipboard
Exception x80004005 “not allowed to write” when trying to (programmatically) eject a USB drive
While using your code, and attempting to eject a USB drive (that has been being used for writing a zip file) the Eject function throws an exception.
I think here
int hr = Native.CM_Request_Device_Eject(device.InstanceHandle, out veto, sb, sb.Capacity, 0);
if (hr != 0)
throw new Win32Exception(hr);
The exception reported is x80004005 "not allowed to write"
However if I do it again the ejection proceeds without problem. It is only the first time the exception is thrown. What could be the cause of this failure? I would appreciate some help on this matter