how do i remove a usb drive with a script?

T

ToddAndMargo

Hi All,

I know this may not be the correct group to post this in,
but I figure you will all forgive me if it is not. ("devcon"
deals with the registry.)

I wrote a customer a batch script that backs up her
internal hard drive to an external USB hard drive.
Problem: she ALWAYS forgets to press the add/remove
icons and just jerks the cord out of the drive (she has three
drives that she rotates). I clear the error by
going into the device manager and doing a remove
on the external drive. (I fear showing her how to
use the device manager.)

Now, I know that there is a way to do this with "devcon" from
my script. Problem: I am not smart enough to figure out how.
Can some kind person tell me 1) the devcon command to
search for the external usb hard drive and 2) how to use
devcon the do the same thing I manually do in the device
manager?

Many thanks,
-T
 
M

Mark V

Hi All,

I know this may not be the correct group to post this in,
but I figure you will all forgive me if it is not. ("devcon"
deals with the registry.)

microsoft.public.win2000.cmdprompt.admin
is another group that might be useful.

[ ]
Now, I know that there is a way to do this with "devcon" from
my script. Problem: I am not smart enough to figure out how.
Can some kind person tell me 1) the devcon command to
[ ]

I can offer no practical help on this one, but note that a Google
search on
remove USB device with devcon
returns a number of interesting looking hits. HTH
 
M

Michael Bednarek

I know this may not be the correct group to post this in,
but I figure you will all forgive me if it is not. ("devcon"
deals with the registry.)

I wrote a customer a batch script that backs up her
internal hard drive to an external USB hard drive.
Problem: she ALWAYS forgets to press the add/remove
icons and just jerks the cord out of the drive (she has three
drives that she rotates). I clear the error by
going into the device manager and doing a remove
on the external drive. (I fear showing her how to
use the device manager.)

Now, I know that there is a way to do this with "devcon" from
my script. Problem: I am not smart enough to figure out how.
Can some kind person tell me 1) the devcon command to
search for the external usb hard drive and 2) how to use
devcon the do the same thing I manually do in the device
manager?

AFAIK devcon allows you to disable a device, which has the effect that
it gets re-installed the next time it's seen. That's IMO not the
equivalent of "Safely Remove Hardware".

To bring up the GUI for "Safely Remove Hardware" from a script:
RUNDLL32.exe SHELL32.DLL,Control_RunDLL hotplug.dll

To actually remove/eject a device, I use:
deveject.exe -EjectDrive:E:
See <ftp://ftp.heise.de/pub/ct/listings/0316-208.zip>.
Note that parameters to deveject are case sensitive.

Further reading:
"DevEject Alternatives"
<http://portableapps.com/node/3160>
which i.a. points to:
<http://www.uwe-sieber.de/usbstick_e.html>.
 
T

ToddAndMargo

AFAIK devcon allows you to disable a device, which has the effect that
it gets re-installed the next time it's seen. That's IMO not the
equivalent of "Safely Remove Hardware".

To bring up the GUI for "Safely Remove Hardware" from a script:
RUNDLL32.exe SHELL32.DLL,Control_RunDLL hotplug.dll

To actually remove/eject a device, I use:
deveject.exe -EjectDrive:E:
See <ftp://ftp.heise.de/pub/ct/listings/0316-208.zip>.
Note that parameters to deveject are case sensitive.

Further reading:
"DevEject Alternatives"
<http://portableapps.com/node/3160>
which i.a. points to:
<http://www.uwe-sieber.de/usbstick_e.html>.

I did not know deveject existed. Thank you!
-T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top