我有一个桌面Java应用程序,使用Swing作为GUI库。我需要在该应用程序中安装一个安装程序,但是它必须拥有管理员权限。
我正在使用
Process p = Runtime.getRuntime().exec(pathToTheExeInstaller);
安装程序时,如果没有管理员权限运行它,则会出现此错误。在NetBeans中使用“Clean and Build”生成的jar文件中是否有一种方法可以在上下文菜单(右键单击菜单)中获取“以管理员身份运行”选项?
我有一个桌面Java应用程序,使用Swing作为GUI库。我需要在该应用程序中安装一个安装程序,但是它必须拥有管理员权限。
我正在使用
Process p = Runtime.getRuntime().exec(pathToTheExeInstaller);
Runtime.getRuntime().exec("powershell.exe Start-Process 'pathToTheExeInstaller' -verb RunAs");
这将会给用户一个提示,询问是否允许你的安装程序获得提升的权限。
摘自这个答案
示例
Runtime.getRuntime().exec("powershell.exe Start-Process 'notepad.exe' -verb RunAs");
~1
,这是createTempDirectory
返回的内容。 - Tarek + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand`
'
而不是 "
. - Roshana Pitigala右键单击“命令提示符”,选择“以管理员身份运行”,然后您就可以
java -jar myprogram.jar