I use ERROR_LEVEL in my login scripts to provide an alternate mapping if
the first one fails. I'm now trying to use the errorlevel result from the
MAP command in a batch file, but it doesn't seem to work in DOS.

Does anyone know whether MAP.EXE actually returns an errorlevel in DOS,
and if so, what the syntax is for using it? I've tried every variation I
can think of, but it doesn't look to me as though it even returns an
errorlevel in DOS, only ERROR_LEVEL when run from the login script. The
batch file is below, along with a sample of the relevant login script
section, which DOES work (thanks to Jason Ganovsky of Novell for
suggesting the idea and providing the correct synttax for that one!).

Background:

We use this batch file (actually run via a NAL App with prompted macros)
to replace the old setup scripts from NWAdmin that got improved away in
ConsoleOne. We create default directories, change the ownership, and
correct the rights assignment (ConsoleOne insists on setting the rights to
RWCEMFA even though the template specifies RWCEMF - it's a "feature".)

If the mapping to the drive fails (usually because one of the parameters
is incorrect), I want it to catch that via the errorlevel, go to an error
message, and end. The current version of the file asks them to check the
mapping, press Ctrl-C to exit if it's wrong, or any key to continue.

This became important when someone root-mapped the same drive letter used
in the batch file to a restricted location on the server, entered the
parameters incorrectly, and didn't notice that the drive mapping failed.
The result changed the ownership of the folders in that location to the
end user he was setting up - and worse, assigned RWCEMF rights to the user
in this folder. Fortunately, we caught it (we think!) before the user
mucked around in there and corrected the ownership and rights. But now I
want to automate the process of cancelling the rest of the batch file if
the drive mapping is incorrect!

Batch File:
@ECHO OFF
IF "%1" == "" GOTO OOPS
IF "%2" == "" GOTO OOPS
IF "%3" == "" GOTO OOPS
IF "%4" == "" GOTO OOPS
MAP ROOT U:=.DOCCS1_NVol1.Services.DOCNet:\Users\%4\%1
IF NOT ERRORLEVEL 0 THEN GOTO BADMAP
ECHO.
ECHO Please confirm that the directory above is correct.
ECHO.
ECHO If not, press Ctrl-C to cancel. Otherwise,
PAUSE
U:
MD Access
MD Excel
MD Mail
MD PowerPnt
MD Web
MD Word
FLAG U:\*.* /NAME=.%1.%2.%3.DOCNet
RIGHTS . RWCEMF /NAME=.%1.%2.%3.DOCNet
GOTO END
:OOPS
ECHO.
ECHO.
ECHO You must enter the user's login ID, container, the
ECHO region (R1, R2, etc.), and site subdirectory (NSP, BSP)
ECHO to populate the home directory.
ECHO.
ECHO.
GO TO END
:BADMAP
ECHO.
ECHO.
ECHO Drive mapping is invalid!
ECHO.
ECHO Please check the parameters and try again.
ECHO.
ECHO.
GOTO END
:END
H:
MAP DEL U:
PAUSE

Login Script
Each workstation has a SITE environment variable set based on the third
octet of the IP address, so the script tries the local server first, then
a default server across the WAN if the local server is down. Using
directory maps lets us change the location without having to change the
login scripts - handy when the script is locked open, a server is down for
maintenance, or we're migrating to new servers.

MAP ROOT W:=.%<SITE>Apps.Maps.DOCNET
IF "%ERROR_LEVEL" != "0" THEN BEGIN
WRITE " "
WRITE "ERROR - Drive not available - trying alternate mapping ...."
WRITE " "
MAP ROOT W:=.Apps.Maps.DOCNET
IF "%ERROR_LEVEL" = "0" THEN BEGIN
WRITE " "
WRITE "Alternate mapping successful!"
WRITE " "
ELSE
WRITE " "
WRITE "Alternate mapping failed - contact the OIT Help Desk!"
WRITE " "
END
END