Search code examples
javajavafxlaunch4j

Java application requires Admin Access to run when placed in Program Files


I am working on a Java (JavaFX) desktop app. I am converting it to exe with launch4j tool and then later creating a setup package using Inno Setup Compiler (default installation path set to C:\Program Files (x86)) The application itself don't need any admin privileges and runs fine when I copy the exe on desktop or run it on drives other than C. (Also works fine if I run it in local appdata folder) But I need to place it in Program Files (x86) directory. The app doesn't open if I install it in that directory so I had to create a manifest file for launch4j so that it asks admin access each time it opens. It works fine that way but admin access is asked everytime in this case.

I need to make this application run without asking admin access each time. If there is any solution, please guide me through it. Any help will be appreciated.


Solution

  • Ok so I kind of figured that out. I guess the jar was having trouble reading from system directories and I had to do some read/write operations on a config file. So I changed the config path to:

    String path = Controller.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "\\Data\\";
    

    Now it creates a folder named "Data" inside jar file and read/write from there. I don't know if this is a bad practice or not but it seems to work pretty good for me.

    Thanks a lot to @user31601 who gave me some hint that helped me figure this solution out.