Dos Prompt Home Page Command Prompt Reference

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. When the end of a batch script is reached, an implied ENDLOCAL is executed for any outstanding SETLOCAL commands issued by that batch script.


If Command Extensions are enabled SETLOCAL changes as follows:

SETLOCAL batch command now accepts optional arguments:

    enable or disable command processor extensions. These arguments takes precedence over the CMD /E:ON or /E:OFF switches. See CMD /? for details.
    enable or disable delayed environment variable expansion. These arguments takes precedence over the CMD /V:ON or /V:OFF switches. See CMD /? for details.

These modifications last 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:

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.



Associated Commands



Top of the Page - Command Prompt Reference Home Page
Last Page Update: 08/03/2012

© Sembee Ltd. 1998 - 2024.

Reproduction of any content on this web site is prohibited without express written consent. Use of this web site is subject to our terms and conditions.

All trademarks and registered trademarks are property of their respective owners. This site is not endorsed or recommended by any company or organisation mentioned within and is to provide guidance only and as such we cannot be held responsible for any consequences of following the advice given.

Sembee Ltd. is registered in England and Wales at 1 Carnegie Road, Newbury, Berkshire, RG14 5DJ.
Registered company number: 4704428. VAT Number GB 904 5603 43.

Server 1