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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.