Search notes:

cmd.exe - delayed variable expansion

With enabled delayed variable expansion, the exlamation point character specifies to substitute the value of an environment variable at run time rather than at »compile« time.
When cmd.exe is started, delayed variable expansion is enabled or disabled by giving either the /v:on or /v:off option.
In a batch file, delayed variable expansion can be enabled with setlocal enableDelayedExpansion.

Index