I have a desktop java application that uses Swing as a GUI library. There is an installer that I have to install inside this application, but it must have administrative privileges.
I am using
Process p = Runtime.getRuntime().exec(pathToTheExeInstaller);
to install the program. But it has this error when running it without administrator privilege:
Is there a way to get Run as administrator in the context menu (the right click menu) in the generated jar file when clean and build is used in NetBeans:
This is what you need,
Runtime.getRuntime().exec("powershell.exe Start-Process 'pathToTheExeInstaller' -verb RunAs");
This will give a prompt to the user asking permissions to get elevated access for your installer.
Extracted from this answer
Example
Runtime.getRuntime().exec("powershell.exe Start-Process 'notepad.exe' -verb RunAs");
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