Normally, if I define one User Windows 10 environment variable (var 1) in terms of another (var 2), var 2 should precede var 1 in alphabetical order for it to work. This is identified here, e.g.
For instance, in the window
this
APYTHONDIR -> C:\Users\user1\myprogs
PATH -> %APYTHONDIR%
works, but this
PYTHONDIR -> C:\Users\user1\myprogs
PATH -> %PYTHONDIR%
does not.
Is there any way of avoiding it? Working around it?
I mean to get a solution that functionally works the same as if the variables were defined via registry (or Control Panel).
I can always use naming to ensure "nested" definitions follow alphabetical order. This is not what I want.
I thought about setting them in the desired order in a startup batch file (autoexec.nt, or whatever is current).
I am not sure if this would work for any application requiring the environment variables.
E.g., octave symbolic integration needing to find python somewhere in the PATH, with the directory in the PATH being added in this way.
EDIT As per the answers by harrymc and myself, and following discussion, this is what I tried:
Creating a file
set_env_vars.batin an arbitrary directory, and set a shortcut to it in%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.Adding a line
set /P PTEST=Enter value for PTESTinset_env_vars.batto make sure the file is being read during logon.Logging off and on. I verified that
set_env_vars.batis read.
Then, I added lines
set ZTEST_DIR=C:\ztest
set YTEST_DIR=%ZTEST_DIR%;C:\ytest
to set_env_vars.bat.
Plus log off / log on.
This didn't give me vars ZTEST_DIR and YTEST_DIR in my environment.
Then, I replaced those with lines
setx ZTEST_DIR C:\ztest
set /P WAITING_DUMMY=Enter value for WAITING_DUMMY
setx YTEST_DIR %ZTEST_DIR%;C:\ytest
in set_env_vars.bat.
(The second line to try giving time to the system to set the first var).
Plus log off / log on.
This gave me vars
YTEST_DIR=;C:\ytest
ZTEST_DIR=C:\ztest
in my environment.


