Solved

Windows System32 folder

Posted on 2004-09-19
18
831 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 25 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 25 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
Technology Partners: 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 25 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 25 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 25 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 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

729 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