Solved

If errorlevel = problems in batch files

Posted on 2011-09-14
3
433 Views
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 

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

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

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

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

:Finish 
Echo **** This Operation has Finished Succesfuly ****

:End
pause
exit

Open in new window

0
Comment
Question by:Contigo1
  • 2
3 Comments
 
LVL 53

Accepted Solution

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

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



~bp
0
 
LVL 1

Author Closing Comment

by:Contigo1
ID: 36537146
This has solved my problem thanks
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36537170
Welcome.

~bp
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

815 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

12 Experts available now in Live!

Get 1:1 Help Now