Solved

If errorlevel = problems in batch files

Posted on 2011-09-14
3
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 54

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 54

Expert Comment

by:Bill Prew
ID: 36537170
Welcome.

~bp
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to put logic for reading multiple repo in a single file 4 106
sqlldr issue 1 35
Why use this lambda? 12 98
AD Computer Objects in VB .Net 2 21
A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…

752 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