Home » Questions » Computers [ Ask a new question ]

Can I define a Windows (XP) environment variable in terms of another environment variable?

Can I define a Windows (XP) environment variable in terms of another environment variable?

I wish to define two environment variables as follows:

Asked by: Guest | Views: 210
Total answers/comments: 2
Guest [Entry]

"Apart from the syntax error found by fretje, if you wish to make these variables permanent, then you need to change the Windows environment variables.

This is done in Control Panel / System / Advanced tab / Environment variables... button.

There is also a nice little product called Rapid Environment Editor (donationware) that provides a clearer user interface.

EDIT

I think I understand now what you're trying to do, but that can only be done by editing the registry. The following Microsoft article explains the process to follow:
How to propagate environment variables to the system.

In a nutshell, for user environment variables you need to go to registry key HKEY_CURRENT_USER\Environment, where all these variables are stored.

There you need to add the two variables as of type REG_EXPAND_SZ (named ""expanded string value"" in regedit). This is the only way to add this type, since Windows by default will only add REG_SZ types which are simply unexpandable.

I tried it just now and it works perfectly well."
Guest [Entry]

"Yes this a really odd behavior that I have never found documented but here is what works.

Using your example above put quotes around the variable in the last line:

dir ""%JAVA_DIR%""

If someone knows the why of this or a link that explains it this would be great. The behavior is consistent though when referring to a variable that has been defined in part with another variable."