Article View: borland.public.jbuilder.java.language
Article #588Re: Put a value to system variables
From: John McGrath [TeamB]
Date: Wed, 16 Mar 2005 21:14
Date: Wed, 16 Mar 2005 21:14
42 lines
2987 bytes
2987 bytes
On 3/16/2005 at 4:22:29 AM, tolis wrote:
> I mean that i want to write(add, give) from my java code a value e.g.
> 'C:\Program Files\Microsoft Office\Office'
> into System Variable of window(Path) (start-->control
> panel-->System-->Advanced-->Enviroment Variables-->System
> Variables-->(Variable = Path and value = 'C:\Program Files\Microsoft
> Office\Office' )
Environment variables are a somewhat system-dependent idea, although the
concept is fairly well supported in most significant operating systems
these days, including Windows, Unix/Linux and Mac OS/X. Basically, we are
talking about a set of name=value strings that is associated with a
process and is inherited from the parent process when a child process is
created.
Java has some support for environment variables. You can get the value of
variables from the current process environment using System.getEnv(), and
you can set the environment for created subprocesses using Runtime.exec()
and the ProcessBuilder class.
When you talk about "system" variables, what you are really talking about
is a Windows system configuration that controls what environment variables
are created for new processes. Not suprisingly, Java does not have any
facilities for manipulating Windows system configuration.
FWIW, Windows stores the system variable configuration in the registry key
HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment. The
Windows registry is also a system-dependent thing, and Java does not have
general facilities for manipulating it (although it does use the registry
for some features). If you want to change this from a Java program, you
will need to resort to some native approach, either JNI, or running a
native program using Runtime.exec().
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<xn0dztqcp7u96nc006@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4236f276@newsgroups.borland.com> <xn0dzsj2u6osrdy003@newsgroups.borland.com> <4237faae@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,f391e0283c1eb2c9 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit From: "John McGrath [TeamB]" <ng-b@JPMcGrath.net> Subject: Re: Put a value to system variables Newsgroups: borland.public.jbuilder.java.language References: <4236f276@newsgroups.borland.com> <xn0dzsj2u6osrdy003@newsgroups.borland.com> <4237faae@newsgroups.borland.com> User-Agent: XanaNews/1.17.2.7 Message-ID: <xn0dztqcp7u96nc006@newsgroups.borland.com> X-Ref: newsgroups.borland.com ~XNS:0000029A MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 NNTP-Posting-Host: 151.201.155.159 Date: 16 Mar 2005 13:14:41 -0800 X-Trace: newsgroups.borland.com 1111007681 151.201.155.159 (16 Mar 2005 13:14:41 -0800) Lines: 42 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail