File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes i want to know how to set envirmnt variabls from javaprogram permanently. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "i want to know how to set envirmnt variabls from javaprogram permanently." Watch "i want to know how to set envirmnt variabls from javaprogram permanently." New topic
Author

i want to know how to set envirmnt variabls from javaprogram permanently.

nilanil kumar
Greenhorn

Joined: Mar 09, 2005
Posts: 9
i am writing a utility which updates some files and database records , using core java,in that i need to modify two of
windows envirement variables programetically,which will have to stay after my jvm closes also(permanently).
for this i find one way by calling a batch file from my program
i am giving the sudo code here

...
if (OS.indexOf("windows 9") > -1) {

////////
//see here ----...>>>>>>
p = r.exec( "command.com /c set > envvar.txt" );
////

}
else if ( (OS.indexOf("nt") > -1)
|| (OS.indexOf("windows 2000") > -1
|| (OS.indexOf("windows xp") > -1) ) {
// thanks to JuanFran for the xp fix!
p = r.exec( "cmd.exe /c set > envvar.txt" );
}
...


there we r setting through command.com(i think its for that consol only) promt i think its not sets permanently
means to stay after jvm closes.
is there any other way of setting parmanently the variables

please give the code for that

i am writing like
if (OS.indexOf("windows") > -1) {
p = r.exec( "env.bat" );
}

but i can't always put this ".bat file with class file.
is there any way that i can embed the bact file in to
the program it self
plase help me in this regards

my batch file is of 2 line only
//////////
@echo off
@SET MESSAGE_SERVR_PORT="someString"
///////

this string again a value which comes from the user when he enters the value in to it.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Would it be allright to reboot the computer before using the environment-variables?

I'm not sure if autoexec.bat is still in use on xp and 2003.
And whether each windows uses win.ini or system.ini.
Or whether you may set environment variables by editing the registry, and how, and which tools ms provides to do so.

But I guess one or more of these ways should work.

(Edit Found a hint in the intermediate forum:
http://java.sun.com/developer/technicalArticles/releases/preferences/
[ April 15, 2005: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: i want to know how to set envirmnt variabls from javaprogram permanently.