A new tool is born, it works very well, have unique features and solve all setx problems: regenv
it works in xp+.
it is better than setx ,pathed, pathman, setenv
it is a fork of the old nice setenv tool
set "var=D:\Bin"
REM ::::: override a system var:
regenv.exe set -nS c "%var%"
REM ::::: append to a system var
regenv.exe set -nS -sa c "%var%"
REM ::::: preppend to a system var
regenv.exe set -nS -sp c "%var%"
REM ::::: create a variable that contains an unexpanded variable
regenv.exe set -nS -sp c "%%var%%"
REM ::::: edit PATH: if you edit PATH it is good to use -x , because -x will convert the reg type from REG_SZ to REG_EXPAND_SZ, because some tools may create a REG_SZ while the default reg type for PATH is/should be REG_EXPAND_SZ
regenv.exe set -nS -sp -x PATH "%var%"
NB: if var contain a backslash at the end, use double backlash:
regenv.exe set -nS c "D:\Bin\\"
REM gaves D:\Bin\
or delete the last backslash:
set "var=D:\Bin\"
REM -- Great example from Strawberry Perl's portable shell launcher: this deletes the final backslash \.
if #%var:~-1%# == #\# set var=%var:~0,-1%
regenv.exe set -nS c "%var%"
:: gaves D:\Bin
it can even create Volatile variables (HKCU\Volatile Environment).
it is really a nice work.
%PATH%
at superuser.com/questions/297947