?
Solved

Windows System32 folder

Posted on 2004-09-19
18
Medium Priority
?
836 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

777 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