Solved

Access to  Win32/NT environment variables in Java?

Posted on 1998-02-06
1
300 Views
Last Modified: 2010-05-18
Is there anyway to access the environment variables of Win32/NT?  Specifically, I'd like to access the "windir" variable as a standard location of an .ini file for my application.  I looked at the output of System.getProperties() and I (at least for my installation of jdk) there is no direct mapping of this variable.

Thanks in advance.
0
Comment
Question by:mwalker
1 Comment
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 1232919
There is no direct way to do this without writing a native method and calling a Windows API.  Here is a more portable way:

You can specify a property to java when you run the interpreter.  If you're running Sun's JDK, you can do it like this:

java -DWINDIR=%WINDIR% myprog.class

Now in your application, you can get the value of WINDIR like:

String windir = System.getProperty("WINDIR");


0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question