In Windows 2008 Server R2, once I set an environment variable in the command line, how can I make it stick? For example, it's easy to write:

set path=%path%;

much easier than the crummy right-click My Computer method. But once I set this, the changes disappear with my command window. How to make them stick? I want to do the same with JAVA_HOME and some others as well.

link|improve this question

50% accept rate
2  
possible duplicate of How do I set PATH and other environment variables? - it has a part on setting variables permanently (short answer: just use setx) – slhck May 26 '11 at 22:37
setx may be best.. But cmd /? also mentions HKLM or HKCU\Software\Microsoft\Command Processor\AutoRun a bat file there could have the set PATH=.... line. – barlop May 27 '11 at 8:05
@barlop: Setting "permanent" envvars through cmd's AutoRun is a hack. The page @slhck linked to has a better location - HKCU\Environment, which is loaded by Winlogon itself. (It's what setx uses, too.) – grawity May 27 '11 at 14:11
setx is exactly what I was looking for, thank you @barlop Post it and I will accept the answer, else I'll answer myself to close this out – Daniel Williams May 27 '11 at 15:49
answer it yourself or better ask slhck to. I didn't post it 'cos as I suggested in my comment. setx is better. if anything, ask slhck to post it! 'cos he got the answer in first! – barlop May 27 '11 at 16:41
show 2 more comments
feedback

1 Answer

up vote 1 down vote accepted

As mentioned in more detail in How do I set PATH and other environment variables?, you can use setx to set a variable permanently:

setx MyVariable "C:\Path\to\Folder"
setx JAVA_HOME "C:\Path\to\Java"

et cetera.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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