Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Windows System32 folder

Posted on 2004-09-19
18
Medium Priority
?
840 Views
Last Modified: 2008-03-17
hi guys, i want to access the windows "System32" folder path, using the following command in java
System.getProperty()

can anyone tell me what the arguments i should pass into the above method to get the "System32" folder path or any other way to do that.
thanks
0
Comment
Question by:Naeemg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +3
18 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 12099682
You cannot get it by default. Here are all the systrem properties you have in java: http://java.sun.com/docs/books/tutorial/essential/system/properties.html

You will need to pass it using the -D argument: java -Dsystem.path=<path to system, folder>
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 100 total points
ID: 12099767
Since JAVA 1.5 (or 5 as they call it now) you can get your environment variables
by:
        String value = System.getenv("key");  // E.g.:    .getenv("TMP");

It worked already in 1.3 but was blocked in 1.4 for some reason.

;JOOP!
0
 
LVL 5

Author Comment

by:Naeemg
ID: 12099784
dear sciuriware thanks for ur reply, but i realy need to access the "System" or "System32" folder of windows.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 24

Expert Comment

by:sciuriware
ID: 12099889
Well, then it's:

      String path = System.getenv("WINDIR");
      File system = new File(path + "\\system");  // System
      File system32 = new File(path + "\\system32");  // System32

What more do you want?

;JOOP!
     
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12099892
P.S.: I checked this on W2000 and W98.

;JOOP!
0
 
LVL 5

Author Comment

by:Naeemg
ID: 12099937
i'm using jdk1.4, when i used this code, an error occurred.

java.lang.Error: getenv no longer supported, use properties and -D instead: WINDIR
at java.lang.System.getenv(System.java:691)

but in used,
System.getProperty("WINDIR-D")  
or
System.getProperty("WINDIR")

it returns null.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12100012
You did not read my comments above: in 1.4 getenv was blocked.

WINDIR is a MSWindows dependent property,
 JAVA has only platform independent properties in System.getProperty()

What you can do is assume that System\ and System32\ always
reside in C:\Windows or C\Winnt\

So, you could say:

String path:
      if(!new File("C:/Windows/System32").exists) //    Yes, use /
      {
             if(!new File("C:/Winnt/System32").exists)
             {
                    System.out.println("CAN'T FIND MY WAY!");
             }
      }
// here you'll have the correct name of system32's parent directory in 'path'.
// b.t.w. I've seen systems at a large company where everything was installed on D:
// so, maybe you should include that too ...

;JOOP!
0
 
LVL 9

Assisted Solution

by:Venci75
Venci75 earned 100 total points
ID: 12100584
qirionis is right - you should start your app using:
java -DWINDIR=%WINDIR% ...

then you will be able to take it using:
System.getProperty("WINDIR");
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12100988
Clumsy! you have to specify that for every system that you will run on!

;JOOP!
0
 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 100 total points
ID: 12101145
Hi Naeemg,

You can get the "java.library.path" property, and parse each path element to find something like <drive>:\winnt\system or <drive>:\windows\system



0
 
LVL 3

Assisted Solution

by:aviadbd
aviadbd earned 100 total points
ID: 12101914
sciuriware,

the -DWINDIR option might be clumsy but safe.. If later on he'll want to use the /sbin or something, he's capable of doing that. And when he wraps the application in an EXE, he can make it a default property.

AviadBD.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12102355
You can't wrap it into an exe and this is not a JAVA solution at all.

;JOOP!
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12103128

But ofcourse you can, dear sciuriware!

http://www.ej-technologies.com/products/exe4j/overview.html

Maybe its my opinion alone, but I think a real Java solution is a solution which leaves the Code cross-platform, and the wrapper (whether its an EXE, shell script, batch, or even a service/daemon) platform-specific.

AviadBD.
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 12408583
I suggest to split the points : girionis, sciuriware, Venci75, Webstorm, aviadbd.

0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12413554

I agree. We all helped here.

Aviad.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

610 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