If I want to add the java \bin to my environment variable, can I do this from the command prompt using the SET command or is that just temporary?
That's just temporary for the current process' environment. There's setx if you'd like to make a more permanent change.
Each process inherits the environment variables from the process that spawned it, and any changes they make using the
SET command are local to that process (and any it spawns after the change) by default.
To make a change to an environment variable that “sticks”, whether for the current user or the whole system, you need to use a special tool. There are plenty of such tools, but I’ll give you a list of the best ones.
There is Microsoft’s SETX as mentioned by Ronald. It can be found in the resource kit or separately from a few Microsoft pages. It is generally a good one that most people will have no problems with. However, testing has found that it can fail to work, or even crash if the value is too long (it seems to have a limit of ~1KB). And as it happens, the
PATHvariable is the most likely variable to get really long…
There is a tool called SetEnv on CodeProject that performs this function. It is my current favorite because I have worked with the author to enhance it and work out some kinks; so it fulfills all of my expectations of such a tool.
There is another third party tool called SETENV which also performs this function.
Also, you could alter the variable through the
Finally, you could go the manual way (I have written a script to do just that in a pinch), where you set the environment string directly to the registry and issue a WM_SETTINGCHANGE message to all top-level windows.
For the record, you asked about adding to the path. There is no default or built-in way to extend an environment variable (although such a function could easily be added to any of the above tools). Rather, when you change a variable, you replace it. Therefore, to add a path to the
PATH variable, you would use a command such as:
But remember that neither of the previous commands will stick, so you can use the former command, replacing the call to
SetEnv, etc. The latter command cannot be made to stick.
From my experience it is temporary, and only effects the command window you issued it in. You have to modify the System settings via Control panel to make it happen for all new windows.