Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

windows vista - UAC and Java

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...