javanetbeansjavafxadmin-rights

Netbeans Deploy JavaFX App Admin Rights


How can I deploy a JavaFX application for Windows so that the exe containing my jar launches with admin rights? I had this working with my old method of deployment, but the Netbeans way seems much easier and more efficient so I would really like to use it. It helps eliminate a lot of extra steps that I normally need to do...

I'm sure the solution is right under my nose, but I just can't seem to figure it out!

Best regards,

Alen


Solution

  • The solution I found works very well for me, here's how I do it:

    1) Define custom JDK location in the jfx-impl.xml file of the JavaFX Netbeans project. Tip: Search for "plat.setBasedir" and change the parameters to: plat.setBasedir("path\to\jdk\and\not\jre"). This ensures the JDK will be embedded in your installer.

    2) Setup native deployment for the JavaFX project (how ever you see fit for your project).

    3) Deploy your application as a native exe.

    4) Install your application locally somewhere.

    5) Install Windows SDK 7.1. You need the manifest tool (mt.exe), you'll find it somewhere in program files/windows sdk/...

    6) Create a manifest for admin rights (examples can be found on stackoverflow or google). Tip: Filename should look something like this when you make it-> "Program Name.exe.manifest".

    7) Use mt.exe to inject the manifest into the .exe of your application. Tip: Start CMD with admin rights and run mt.exe like so -> mt.exe -manifest "path\to\manifest\Program Name.exe.manifest" -outputresource:"\path\to\exe\that\needs\elevation".

    8) After injecting the manifest in step 7, create your own setup with INNO Setup that repackages the exact structure that was created by the native deployment function of Netbeans (This will now include your newly elevated .exe in the new setup).

    Basic idea:

    Deploy with Netbeans -> Install locally -> Inject elevation manifest -> Repackage with INNO Setup creator