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 51

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 51

Expert Comment

by:Bill Prew
ID: 36537170


Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

747 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

11 Experts available now in Live!

Get 1:1 Help Now