Eject a Removable USB drive

Rickey, Kyle W Kyle.Rickey at bakerhughes.com
Tue Mar 10 09:39:46 EDT 2009


def do_magic():
    from staples import easy_button
    result = easy_button.press()
    return result

:) In all seriousness that code did the trick but only after a short delay. I noticed when I first ran it, there was no effect. But when I ran it interactively, it succeeded.

Is there any way to check that the drive is still showing up in explorer and then re-run the code? Something like:

while drive_exists:
	shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, "F:\\")


Right now I've got:

time.sleep(1)
shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, "F:\\")


Thanks for your help!

-Kyle Rickey

-----Original Message-----
From: python-list-bounces+kyle.rickey=bakerhughes.com at python.org [mailto:python-list-bounces+kyle.rickey=bakerhughes.com at python.org] On Behalf Of Aaron Brady
Sent: Monday, March 09, 2009 6:15 PM
To: python-list at python.org
Subject: Re: Eject a Removable USB drive

On Mar 9, 6:08 pm, Mark Hammond <skippy.hamm... at gmail.com> wrote:
> 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...)

Yay, magically!  import crystalball?
--
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list