I want to expand the Path registry variable's value with a value of a batch file variable
:: This is the content of the install.cmd
set ROOT_DIR=%~dp0%
echo %path%|find /i "%ROOT_DIR%\Tools\">nul || set path=%path%;%ROOT_DIR%\Tools\
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d %path% /f
Expected: it appends the %ROOT_DIR%\Tools to the %path% if it does not contain already, then write out the whole path to the Path Registry entry
Actual: Invalid syntax
Variation 1
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d ^%path^% /f
Result: it ignores the force switch, remove everything from the Path and overwrite it with a '/f' string
Variation 2
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d %%path%% /f
Result: it overrides the content of the Path registry entry with a "%path%" string (not with its value)
Variation 3
reg.exe ADD "HKEY_CURRENT_USER\Environment" /v Path /t REG_EXPAND_SZ /d path /f
Result: it overrides the content of the Path registry entry with a "path" string (not with its value)