1

I wondering to make a batch file that have purposed like this :

when a usb drive that ejected on my notebook is succesfully unmount, I want to make my windows is shutdown.

So, I use RemoveDrive.

Assumed, I mounted my flash drive to E, I use this command

RemoveDrive.exe E: -L

it gives me message like this :

Removing 'My drive'(E:)
success

Now, I was wondering to make a batch file (.bat), when success, it execute 'shutdown / s'. if failed, it gives me just a message error. How come ? Amy help it so appreciated.

Edit : based this web : FAQ it said :

0 - successfully removed a device
1 - device identified but not removed
2 - device not found or parameters are invalid
4 - RemoveDrive.exe located on the drive to remove -> temporary copy 
    created and executed

so this is my code so far :

@ECHO OFF
set def="0"
SET /P uname=Enter the drive (letter:): 
IF "%uname%"=="" GOTO Error
    RemoveDrive.exe "%uname%" -L
if %ERRORLEVEL% == def
  shutdwon /s
else
  echo 'Something have problem'
GOTO End
:Error
ECHO Please enter your drive's name! 
:End

if success or failed, it still gives me the syntax of command is inicnorrect message

Fadly Dzil
  • 2,154
  • 3
  • 34
  • 85
  • What is that error-message of the message error? And why do I ask? – Patrik Jun 22 '15 at 11:44
  • let say, it invalid drive : , the message is 'abort'. – Fadly Dzil Jun 22 '15 at 11:49
  • FWIW, you can invoke the "Eject" verb via WSH's `Shell.Application` object to safely dismount removable drives. See http://stackoverflow.com/a/27234424/1683264 – rojo Jun 22 '15 at 16:57
  • 1) `shutdwon`? 2) `%errorlevel%` will never be `def` (possibly it will be `%def%`). 3) No parantheses with `if`-`else` statement used. – Stephan Jun 23 '15 at 06:22

1 Answers1

0

As per if command syntax and explanation in Command-Line Reference:

if %ERRORLEVEL% == def (
  shutdown /s
) else (
  echo 'Something have problem'
)
JosefZ
  • 28,460
  • 5
  • 44
  • 83