Solved

If errorlevel = problems in batch files

Posted on 2011-09-14
3
436 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 56

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 56

Expert Comment

by:Bill Prew
ID: 36537170
Welcome.

~bp
0

Featured Post

Technology Partners: 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

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Starting up a Project
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…

623 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