Is there a way in Java to ask the system to get control over administrator functionality. Of course without doing: Right click on the exe -> run as admin.
What I want is that there comes a frame from UAC like in Windows Vista or Windows 7.
Or have I to do some settings while making an exe from the jar?
First: open CMD as administrator and open jar:Start > cmd > right click > run as administrator.
Runtime. getRuntime(). exec("c:/elevate Rundll32.exe Powrprof. dll,SetSuspendState ");
Again, right-click on the app's name. Click on Properties and select the Shortcut tab. Select Advanced. Finally, mark the checkbox next to Run as administrator.
You have to create a manifest file that specifies that your application needs administrator permissions. You can include the manifest in your exe or keep it as a separate file (yourapp.exe.manifest)
http://msdn.microsoft.com/en-us/library/bb756929.aspx
The easiest way would be to use a wrapper to launch your JVM, then elevate the wrapper. I use a simple NSIS installer script with the UAC plugin to do this:
; Java Launcher ;-------------- ; You want to change the below lines Name "my program" Caption "my program Launcher" Icon "iconfile.ico" OutFile "java launcher.exe" ; param below can be user, admin RequestExecutionLevel admin !include UAC.nsh SilentInstall silent AutoCloseWindow true ShowInstDetails show Section "" ; command to execute StrCpy $0 'javaw -jar myjarfile' SetOutPath $EXEDIR Exec $0 SectionEnd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With