Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get the window default installation path

 
prabhu ganapathylingam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I am trying to find the window installation path using a java program. is there any way to find the path. help me
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General.

What do you mean with Windows installation path? The folder in which Windows is installed? Then use System.getenv("WINDIR"). On my machine that returns C:\WINDOWS.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.getenv("windir") ? Not sure it applies to all Windows versions...
 
prabhu ganapathylingam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanks for reply. I want to find the path while installing the software where it is going to installed. how to find this.


 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your program won't know where you will install it. The installer itself probably will; for instance, InnoSetup uses {app} for the application installation folder.

Why do you need this?
 
prabhu ganapathylingam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created an executable file. the user can install it where ever he wants it may be c:,d: or something
i want to find the path where the application is installed
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't created an executable file; you've created an executable JAR. Small difference but important enough to mention. JAR files are more limited than executables (e.g. no icon).

Technically it isn't possible to get the path of a JAR file. There are a few tricks however; search for my posts in this forum. Look for ProtectionDomain as search word.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic