Page 1 of 1

help what is the command that eject the usb drive [solved]

Posted: 02 Dec 2011 22:48
by abc0502
Hi, i'm trying to make a batch file that work from a usb drive
the batch will close the running programs on the usb and then eject the usb
my problem in the eject part ... what is the command for ejecting the usb drive.
i searched and many say there is no command but then how the windows eject the device then?
help please

Re: help what is the command that eject the usb drive

Posted: 03 Dec 2011 09:05
by Ed Dyreen
'
Eject ? On a USB ?, you mean safely remove, dunno but you may want to disable it
( same effect as safe remove, flushes all buffers to disk ).
You can use DevCon, available from http://www.ed-dyreen.com/eDOS%20beta%20 ... 7.11.2011/
Find the device for your class which is 'USB: USB-controllers' and disable the device.
something like:

Code: Select all

@echo off
DevCon.EXE /?
DevCon.EXE classes
DevCon.EXE help FindAll
pause
exit 0

Code: Select all

for %%! in ( "USB"
) do (
   for /f "tokens=1* delims=: " %%A in ( 'DevCon.EXE FindAll ^=%%~! ^|findstr /i /c:":"'
   ) do (
      set "ID=%%A"
      set "DEVICE=%%B"
      set "HWID=!ID:~0,21!"
   )
)
"DevCon.EXE" disable !HWID!
You may want to try http://unattended.msfn.org/unattended.xp/ ( they also have a forum ).
You will find more information on those subjects there.

Re: help what is the command that eject the usb drive

Posted: 04 Dec 2011 19:27
by abc0502
Thanks for the help :)