1
0 Comments

It has been observed that when defining one User Windows 10 environment variable (var 1) in terms of another (var 2), var 2 must be listed before var 1 in alphabetical order for it to function properly. An example of this can be seen in the following set of variables:

APYTHONDIR -> C:\Users\user1\myprogs PATH -> %APYTHONDIR%

This configuration works as intended, but the following does not:

PYTHONDIR -> C:\Users\user1\myprogs PATH -> %PYTHONDIR%

Is there a way to achieve the desired result without adhering to the alphabetical order requirement? Is it possible to use a solution that functions similarly to setting the variables through the registry or Control Panel?

One potential solution is to set the variables in the desired order using the setx command. Another option is to use the Windows registry, by navigating to the key HKEY_CURRENT_USER\Environment in the registry editor and adding the variables there.

It is also possible to set the variables in a startup batch file, such as autoexec.nt. However, it is not certain whether this would work for all applications that require the environment variables. For example, Octave’s symbolic integration may not be able to locate Python in the PATH if the directory is added in this way.

As a side note, it is possible to ensure that “nested” definitions follow alphabetical order by using naming conventions. However, this is not the desired solution in this case.

To further clarify, the user attempted to set the variables using a startup batch file, but this did not produce the expected result. They then tried using the setx command, but this also did not work as intended. The resulting variables were YTEST_DIR=;C:\ytest and ZTEST_DIR=C:\ztest.

Askify Moderator Edited question April 16, 2023