previous | start | next


SETLOCAL

Begins localization of environment changes in a batch file.
Environment changes made after SETLOCAL has been issued are
local to the batch file.  ENDLOCAL must be issued to
restore the previous settings.

SETLOCAL

If Command Extensions are enabled SETLOCAL changes as follows:

SETLOCAL batch command now accepts an optional argument, which can be
either ENABLEEXTENSIONS or DISABLEEXTENSIONS.  This will enable or
disable the Command process extensions until the matching ENDLOCAL
command, regardless of their setting prior to the SETLOCAL command.

The SETLOCAL command will set the ERRORLEVEL value if given
an argument.  It will be zero if one of the two valid arguments
is given and one otherwise.  You can use this in batch scripts
to determine if the extensions are available, using the following
technique:

    VERIFY OTHER 2>nul
    SETLOCAL ENABLEEXTENSIONS
    IF ERRORLEVEL 1 echo Unable to enable extensions

This works because on old versions of CMD.EXE, SETLOCAL does NOT
set the ERRORLEVEL value. The VERIFY command with a bad argument
initializes the ERRORLEVEL value to a non-zero value.

Back to the top of this page  



previous | start | next