Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to set three environment variables and append them to the machine path. Right now my code is like this:

setx CATALINA_HOME "C:\Program Files (x86)\Apache Software Foundation\Tomcat 7" /m
setx JRE_HOME "C:\Program Files (x86)\Java\jre7" /m
setx JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_21" /m

The first three when run alone work fine for adding the variable. However, the last line is resulting in the deletion of part of the original path and none of the additional variables appended.

My desired result would be the addition of the three variables and for the system-wide path to be

[original path];%JAVA_HOME%\bin;%JRE_HOME%\bin;%CATALINA_HOME%\BIN;
share|improve this question

3 Answers 3

Part of your problem is that SETX isn’t SET –– after you do

setx JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_21" /m

…, %JAVA_HOME% isn’t set in that instance of the Command Prompt.  You’d have to start a new instance to get %JAVA_HOME%, et. al., set.  I suggest you do something like

set  JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_21

I don’t see why you would be deleting part of the original path.  Access/modify the User path variable, not System path may be relevant.  And you might want to do

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v path

to get the system part of the PATH variable, excluding the user part.

share|improve this answer
HKCU\Environment for user vars. and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment for system.vars. PATH combines/concatenates them –  barlop May 3 at 14:35
@barlop: I don't understand what you are saying. –  Scott May 3 at 21:23
i'm not contradicting what you are saying. And i'm saying that if you type PATH<ENTER> you'll see it first lists the system path, then the user path. i.e. the contents of the PATH variable is made up of both the registry entry for the system/machine path, and the registry entry for the user path. For example, the first entry of %PATH% is the first in the system path, and the last entry is the last in the user path. because if concatenates(joins) the values from the two entries, first the system path then the user path after it. –  barlop May 3 at 22:01
OK;  I was assuming that the OP already knew that, from the fact that the question mentions "system-wide %PATH%", "the machine path", and "the system-wide path", and he was already using the /m option to setx. –  Scott May 3 at 22:31
He didn't know the registry entry for it that's why you mentioned it. And my point is that if you're going to educate somebody about where that is it's worth, for reference, also mentioning where the user path entry is. Then he can really understand how something can be in one and not the other. In fact no doubt you'd have had to look up the system path registry entry (as it's rather long), and most information sources that list it are helpful enough to list the user one too. And having both there is useful for anybody for reference or if they don't know then to help them understand. –  barlop May 4 at 9:03

If you use %var%, it is expanded at use. If you want to set a variable to include %var%, you need to write %%var%%.

Note also the registry settings are not seen by the current process, but are seen only by new processes. In winpe, these settings in registry are never passed to new processes, but the cmd environment gets the explorer environment, not the registry. For this reason people have written utilities rthat fiddle different environments.

If you want to read registry to the current cmd session, you may need something like Frank Westlake's conset.exe.

share|improve this answer

I've found that placing the /M switch early does the trick, even though they want you to place it at the end.

So for instance, this works:

setx /M PATH "%PATH%;C:\AddYourPathHere"

But this doesn't:

setx PATH "%PATH%;C:\AddYourPathHere" /M
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.