Solved

Windows System32 folder

Posted on 2004-09-19
18
811 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert ArrayList of custom objects to JSON 4 53
countPairs challenge 7 58
java set up 1 46
firstChar challenge 13 84
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now