Discussion:
retrieving standard program path from Windows
(too old to reply)
Oliver
2005-06-08 13:29:16 UTC
Permalink
Hi,

at the moment im trying to retrieve the standard program path ("C:\Programme" or "C:\Program Files" or ... itŽs language dependent) from Windows 2000 with my Java program (JDK 1.5).
Does somebody have an idea?

I had a look at java.lang.System, here i get the user.dir (working directory) by

String s = "";
Properties P = java.lang.System.getProperties();
s = P.getProperty("user.dir");
return s;

but this is not exactly what i want.

thanks

Oliver
Shankar Unni
2005-06-09 01:00:38 UTC
Permalink
Post by Oliver
at the moment im trying to retrieve the standard program path ("C:\Programme"
or "C:\Program Files" or ... it´s language dependent) from Windows 2000
with my Java program (JDK 1.5).
Have you tried looking for an environment variable (or property) called
"ProgramFiles" or "PROGRAMFILES" (depending on which sort of shell you
start your program from)?
Lori M Olson [TeamB]
2005-06-09 02:07:02 UTC
Permalink
Post by Shankar Unni
Post by Oliver
at the moment im trying to retrieve the standard program path
("C:\Programme"
or "C:\Program Files" or ... it´s language dependent) from Windows 2000
with my Java program (JDK 1.5).
Have you tried looking for an environment variable (or property) called
"ProgramFiles" or "PROGRAMFILES" (depending on which sort of shell you
start your program from)?
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getenv(java.lang.String)

On my Windows 2003 Server, the environment variable is "ProgramFiles"

Note that System.getenv() was deprecated from JDK 1.1 to JDK 1.4,
resurfacing in JDK 1.5.
--
Regards,

Lori Olson [TeamB]

------------

Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.

Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Oliver
2005-06-09 08:12:55 UTC
Permalink
Hello,

ok, many thanks.
Note that System.getenv() was deprecated from JDK 1.1 to JDK 1.4, >resurfacing in JDK 1.5.
Ok, now i have one question still: i have another (similar) project in JDK 1.4. Is there another possibility in 1.4 to retrieve the ProgramFiles Dir?

regards

Oliver
Lori M Olson [TeamB]
2005-06-09 22:18:54 UTC
Permalink
Post by Oliver
Hello,
ok, many thanks.
Post by Lori M Olson [TeamB]
Note that System.getenv() was deprecated from JDK 1.1 to JDK 1.4,
Post by Lori M Olson [TeamB]
resurfacing in JDK 1.5.
Ok, now i have one question still: i have another (similar) project
in JDK 1.4. Is there another possibility in 1.4 to retrieve the
ProgramFiles Dir?
regards
Oliver
Not without the use of JNI.
--
Regards,

Lori Olson [TeamB]

------------

Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.

Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Shankar Unni
2005-06-10 23:10:50 UTC
Permalink
Post by Lori M Olson [TeamB]
Not without the use of JNI.
Or by the classic dodge of exec'ing a helper program to write out the
values of environment variables:

Process p = Runtime.getRuntim().exec("cmd /c echo '%PROGRAMFILES%'");
// Read the output from p.getOutputStream()
Oliver
2005-06-13 14:54:59 UTC
Permalink
Hello,

thank you both. I have one little remaining question: how can i read from the OutputStream? (toString() returns the address of the object, but where is the content?)

Oliver
Post by Shankar Unni
Post by Lori M Olson [TeamB]
Not without the use of JNI.
Or by the classic dodge of exec'ing a helper program to write out the
Process p = Runtime.getRuntim().exec("cmd /c echo '%PROGRAMFILES%'");
// Read the output from p.getOutputStream()
Shankar Unni
2005-06-13 17:57:54 UTC
Permalink
Post by Oliver
how can i read from the OutputStream?
Whoops. I meant Process.getInputStream(), which contains the output of
the process. Read from it like any other InputStream.
Paul Nichols (TeamB)
2005-09-15 03:11:10 UTC
Permalink
Post by Shankar Unni
Post by Oliver
how can i read from the OutputStream?
Whoops. I meant Process.getInputStream(), which contains the output of
the process. Read from it like any other InputStream.
Once you get the InputStream class, you read it as you would any other
InputStream. I would recommend you place it in a BufferedStream type class
however (like BufferedReader).

Loading...