dimanche 19 avril 2015

How execute a command in batch-file if errorlevel is not zero?

I created a simple batch file which would enable me to connect to the internet.

I made it this way- If the connection is successful a message is displayed stating "connection successful" using VBscript and display a message stating "connection failure" if the connection is not established. I made this using if-else statements and errorlevel command, but I am not able to display the failure message using 'errorlevel == 1' command.I mean that if there was an error in the connection process the success message is displayed instead of failure message.


Here's the code in my batch file.



rasdial "TATA PHOTON+" internet

@echo off
if ERRORLEVEL == 0 (echo MSGBOX "Connection successfully established to TATA PHOTON+" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q)
else if ERRORLEVEL == 1 (echo MSGBOX "ERROR: Unable to establish connection" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q
)

Aucun commentaire:

Enregistrer un commentaire