UAC and Java

joegester picture joegester · Jul 2, 2009 · Viewed 9.3k times · Source

Is it possible to ask for elevated permissions from within a Java Application? Suggestions I've seen seem to all be centered around running an external executable or setting up a manifest to request privileges on launch. These aren't available to, for instance, applets. Is there any way to request elevation from a running application?

Answer

Kevin Day picture Kevin Day · Jul 3, 2009

UAC is not something that a running process can request (doesn't matter what language you are running in). You have to request elevation at launch time.

The way that most windows apps handle this (and make it look like they are requesting elevation) is to spawn an extra copy of themselves, requesting elevation, and passing sufficient command line arguments to the new process so that the appropriate dialog can be displayed.

This is why UAC elevation in a dialog is always initiated by a button click that opens a new dialog.

So, in the Java world, you just have to do exactly what everyone else has to do: launch your app again, requesting elevation. There are several ways to launch elevated, the 'run as' verb probably being the easiest.