In tip 4860, we used the CALL command to expand nested environment variables.

You can also use delayed expansion:

set work=!string:%substring%=!
if not "%work%" EQU "%string%" @echo %string% contains %substring%.

Using this approach, I have re-written the CheckPath.bat sample from tip 4860:

                              @echo off                              setlocal ENABLEDELAYEDEXPANSION                              if \{%1\}==\{\} @echo Syntax: CheckPath Folder&endlocal&goto :EOF                              set fold=%1                              set folder=%fold:"=%\;                              set folder=%folder:\\;=\;%                              set found=N                              :: Retrieve System Path.                              for /f "Skip=2 Tokens=1,2*" %%i in ('REG QUERY "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PATH') do (                               set syspath=%%k;                              )                              set work=!syspath:%folder%=!                              if "%work%" NEQ "%syspath%" set found=Y&goto ans                              set folder=%folder:\;=;%                              set work=!syspath:%folder%=!                              if "%work%" NEQ "%syspath%" set found=Y                              :ans                              @echo %found%                              endlocal