IF Command Fails, Echo a Message to the User Batch Script Question

I have a bat file that has the following commands. I want to add a command wherein if these or one of these commands fail, I want to write a message such as "Please contact your IT Manager or IT helpdesk for further assistance"

start cscript \\ShareServer\Shared\Files\Map.vbs
start copy "\\ShareServer\Shared\Files\file.ini"  "C:\Program Files\Software\"

PLease advise!

Thank you!!
mmoyaAsked:
Who is Participating?
 
bklyn2001Connect With a Mentor Commented:
Assuming you want a popup, create a script containing your error message (ex. contactit.vbs):

wscript.echo "Please contact your IT Manager or IT helpdesk for further assistance"

Remove "start" from the bat file and put a line like this after each call:

cscript \\ShareServer\Shared\Files\Map.vbs
if errorlevel 1 wscript contactit.vbs
copy "\\ShareServer\Shared\Files\file.ini"  "C:\Program Files\Software\"
if errorlevel 1 wscript contactit.vbs

Open in new window

0
 
Bill PrewCommented:
You can't really determine of the VBS or COPY worked correctly from the BAT script you are STARTing them from.  You can do this:

start cscript \\ShareServer\Shared\Files\Map.vbs
if errorlevel 1 goto :Errors
start copy "\\ShareServer\Shared\Files\file.ini"  "C:\Program Files\Software\"
if errorlevel 1 goto :Errors
exit /b
:Errors
echo Contact IT..."
exit /b

Open in new window

But that will only trap if the START command failed to run the script or command, not if it actually ran.

Just curious, why are you using START with these anyway?  If you just ran the COPY for example from this BAT file, then you could check its errorlevel.

~bp

0
 
bklyn2001Commented:
billprew makes a good point.  most likely you'll want the error checking to happen inside Map.vbs.  checking errorlevel in the main batch script will only determine if Map.vbs could be run (with or without errors).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.