Eject a Removable USB drive

Rickey, Kyle W Kyle.Rickey at bakerhughes.com
Mon Mar 9 22:20:54 CET 2009

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.

-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 MRAB
Sent: Monday, March 09, 2009 2:10 PM
To: python-list at python.org
Subject: Re: Eject a Removable USB drive

Rickey, Kyle W wrote:
> Hello everyone,
> I would like to be able to eject a usb drive based on drive letter.
> done a bit of googling and came across the CM_Request_Device_Eject 
> function on MSDN
> However, I am not quite sure how to supply the necessary parameter to 
> the function (dnDevInst).  Does it have anything to do with:
> win32file.GetVolumeNameForVolumeMountPoint("F:\\")
> I'm kind of thinking that I have to get some handle to my removable 
> drive and then go up the device tree using CM_Get_Parent
> (http://msdn.microsoft.com/en-us/library/ms791198.aspx) and then call 
> CM_Request_Device_Eject on the appropriate node.
> I am on the right track with this? Any help would be greatly
This article might help:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: eject.py
Type: application/octet-stream
Size: 904 bytes
Desc: eject.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20090309/5ce0478c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: disk.PNG
Type: image/png
Size: 23567 bytes
Desc: disk.PNG
URL: <http://mail.python.org/pipermail/python-list/attachments/20090309/5ce0478c/attachment.png>

More information about the Python-list mailing list