3

I'd like to programmatically launch an application (a second JVM) from a Java app using JNA.

Please note that I can't :

  • add a Windows manifest to the JVM (minimal impact on the client)
  • use right click "runas administrator" (clicking "Allow" in the UAC dialog will be complicated enough)

I've seen other Questions with answers that states "use an exe" like Java: run as administrator but I was wondering if anybody tried this using JNA

Community
  • 1
  • 1
Cerber
  • 2,889
  • 4
  • 27
  • 43

1 Answers1

1

To start an application with elevated privileges, you have to use ShellExecute and pass "runas" as the value of lpOperation parameter. This method does not require you to modify the JVM to add manifest to it. This behaves as if user right-clicked the application and selected Run as administrator command.

Note: on Windows XP, you should not use "runas" because it prompts for user credentials.

Alexey Ivanov
  • 11,541
  • 4
  • 39
  • 68