This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Setting persitent system environment variables using java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Setting persitent system environment variables using java program" Watch "Setting persitent system environment variables using java program" New topic
Author

Setting persitent system environment variables using java program

Biju moozhikkara
Greenhorn

Joined: Oct 21, 2005
Posts: 20
hai,
Iam tryng to write installation for an application,which require to set some persistent system environment variables using java program. I have tried using set command Runtime.getRuntime().exec("cmd /c set blah blah "),but this applies only to that particular DOS promt only,i presume.And this is not perisistent.please do help.
Biju
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Is autoexec.bat still read from Windows? Which windows?
Then open that file, and append your line.
This should take effect on the next boot (no problem: windows users are used to reboot often).

But hasn't it been autoexec.nt for win2k?

Not an java-advanced but general-computing/ beginners question imho.


http://home.arcor.de/hirnstrom/bewerbung
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Java's Preferences class will stick stuff in the windows registry for you. Can't be more persistant than that.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Do these values need to be global for the whole system? What if you happen to choose a variable name that is already in use? I suggest that you create a .properties file and use the Properties class to store these values instead. That way they are local to your own program and don't interfere with any global settings that are necessary for the computer to run. Also, this approach will make your software independent of the operating system. The approach you are using now is specific to Windows.

Layne


Java API Documentation
The Java Tutorial
Biju moozhikkara
Greenhorn

Joined: Oct 21, 2005
Posts: 20
Mr Stefan Wagner
iam working in windows 2000 env and i dont think there is any autoexec.bat file in window 2003.
Any way i got a break through.Thanks for tour reply.
Biju
Mr Barry Gaunt,
i think Java's Preferences can set values to HKEY_LOCAL_MACHINE/JavaSoft/Prefs only ,it can't
environment variables.please read the question carefully.Thank you
Biju
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting persitent system environment variables using java program