7

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

Alen
  • 145
  • 1
  • 1
  • 10
  • Seriously? 2 months and only 16 views? – Will Dec 06 '14 at 13:31
  • @Will just a quick question, when you run .exe file do you want to run it as Admin just by double clicking on it, or you want to exeute the jar inside by clicking on .exe file -> run as admin ? – Maciej Cygan Dec 13 '14 at 00:38
  • Both, preferably. I know (or THINK, at least) that you need to code-sign to run a .jar elevated... – Will Dec 13 '14 at 03:48

3 Answers3

1

After submitting the bounty I may have an answer for you : If you know how to use a custom INNO script with the JavaFX bundler, you can use a custom INNO script and add an entry to the registry that will force the application to run elevated :

[Registry]
Root: HKCU; Subkey: "Software\Microsoft\Windows NT\CurrentVersion\Appcompatflags\layers"; ValueType: string; ValueName: "{app}\File Name.exe"; ValueData: "RUNASADMIN";

This is NOT ideal (to me, anyway), but the most important thing is that it WORKS.

If you need more clarification on it please let me know and I can walk you through it.

Will
  • 3,413
  • 7
  • 50
  • 107
  • Thanks Will! However I found a solution that works. Sorry for the late reply. I'll post it in the answer. – Alen Jun 25 '15 at 09:13
0

Add an application manifest to indicate that the executable should be elevated. See this MSDN blog entry. Add the static application manifest (not embedded) to your project, as a resource.

user314104
  • 1,528
  • 14
  • 31
  • How exactly does one do this in NetBeans. This is a Java application, not a Windows application. – Will Dec 12 '14 at 18:46
  • The OP said it's an .exe containing your .jar. Java applications aren't contained in .exe's -- they're contained in .jar files. Furthermore, Java has no notion of system-level "admin rights". In NetBeans, whatever process the OP used to make the .exe should have a process for creating resource files. Were I in OP's shoes, I'd be using Maven and tying that into the Janel launcher (.exe), and as part of the Maven build process, copying Janel's stub to MyApplication.exe and copying MyApplication.exe.manifest from the `res/` directory. – user314104 Dec 13 '14 at 06:16
  • Hey thanks for the reply! I've found a solution which includes this manifest you speak of, I'll post the solution to answer my own question. – Alen Jun 25 '15 at 09:14
0

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

Alen
  • 145
  • 1
  • 1
  • 10