Skip navigation

JSI Tip 2541. Windows 2000 environment varialbe delay expansion.

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.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.