Search code examples
javawindowsinstallation-path

Finding Application's Installation Directory on Windows using Java


I have a java Application for which I have made an installer. In code, I need to know about where user have installed the application, as it is up to the user to install the application in his favorite directory. So how do I get this information using java code? I need it specific to windows platform.


Solution

  • It's difficult to find out where application is installed, as it is left up to user. So one way to get the application's installation directory is using environment variables on windows machine. When you make the installer, set an environment variable (you can create new one say "XYZ" variable or also can use to an existing one), and set its value to application directory(as you didn't mention the installer you are using so I am not able to tell how would you do this in building the installer for your application). Once you have done this, you can get value of this environment variable in java code, which will give you the installation directory of your Application. here is code for getting value of env var XYZ:

    System.getenv("XYZ");