Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If errorlevel = problems in batch files

Posted on 2011-09-14
3
Medium Priority
?
439 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 59

Accepted Solution

by:
Bill Prew earned 2000 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 59

Expert Comment

by:Bill Prew
ID: 36537170
Welcome.

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

916 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