UAC and Java

后端 未结 5 938
渐次进展
渐次进展 2020-12-10 12:18

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 setti

5条回答
  •  悲&欢浪女
    2020-12-10 12:41

    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.

提交回复
热议问题