Solved

Windows System32 folder

Posted on 2004-09-19
18
822 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
  • 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

809 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