Eject a Removable USB drive

Mark Hammond skippy.hammond at gmail.com
Mon Mar 9 19:08:43 EDT 2009


On 10/03/2009 8:20 AM, Rickey, Kyle W wrote:
> Thanks for the link! That code has got me on the right track. I've
> almost got it working with one small kink.
>
> After the code runs my drive still shows up on Windows Explorer but as a
> removable drive. If I try to double click on it, it tells me to insert a
> disk (see screenshot).
>
> So it seems my code is unmounting my volume, but not the actual device.
> Any ideas? I've attached the code I've got so far.

Adding the following after your eject code runs:

from win32com.shell import shell, shellcon
shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, 
"F:\\")


seems to work for me (well - I actually did the above interactively 
after your code ran, and the disk magically vanished from explorer...)

Cheers,

Mark



More information about the Python-list mailing list