When the command processor reads a line of text, it expands any environment variables present.

You can direct the command processor to interpret !variable! as a delayed environment variable, to be expanded only when used.

Delayed expansions allows you to include variables in compound conditional statements, preventing them from being expanded before they are tested.

The delayed expansion can be configured using the CMD /V:ON and CMD /V:OFF switches or by using Regedt32 to navigate to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor

Edit or Add Value name DelayedExpansion as a REG_DWORD data type. Set the data value to:

0 - Delayed expansion is NOT enabled. This is the default.

1 - Delayed expansion is supported.

NOTE: This Value Name can also be configured at HKEY_CURRENT_USER, which would take precedence over HKEY_LOCAL_MACHINE.

NOTE: The /V: command line switch takes precedence over the registry entries.