If errorlevel = problems in batch files

Posted on 2011-09-14
Last Modified: 2012-05-12
Hi I am trying to do a pretty basic script to map a drive but I am having problems with the if error level =  command

It takes you to the Error page not matter what the outcome is. My script is below.

@Echo off 

Echo **** his script will map a network drive for you ****
Cd %windir%\system32
Goto :PropertySet

Echo **** Please Enter the Valid information ****
Set /P DRIVE="Please Enter the Drive letter here:"
Set /P PATH="Please Enter the Path here:"
Goto :MapDrives

Color 0f
Echo **** Maping the Drive ****
net use %DRIVE%: %PATH%
If %ErrorLevel% equ 1 (Goto :Finish Else (Goto :Error) 

Echo **** An Error has Occured Please make sure you selected a valid free drive letter and a the path you selected is correct. ****
Goto :Finish 

Echo **** This Operation has Finished Succesfuly ****


Open in new window

Question by:Contigo1
  • 2
LVL 52

Accepted Solution

Bill Prew earned 500 total points
ID: 36537087
Syntax should be:

If %ErrorLevel% equ 1 (Goto :Finish) Else (Goto :Error)


Author Closing Comment

ID: 36537146
This has solved my problem thanks
LVL 52

Expert Comment

by:Bill Prew
ID: 36537170


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now