• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

nilanil kumar
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

this string again a value which comes from the user when he enters the value in to it.
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
[ April 15, 2005: Message edited by: Stefan Wagner ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!