如何使用java运行setup.exe文件
作者:互联网
我正在开发一个java应用程序,我必须从中运行xyz_setup.exe安装程序.我尝试了以下代码
String command = "C:\\xyz_setup.exe";
Runtime.getRuntime().exec(command);`
但它抛出了以下错误
java.io.IOException: Cannot run program "C:\Users\NewtonApples\Downloads\idman614.exe": CreateProcess error=740, The requested operation requires elevation
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at upendra.OpenExternalApplication.main(OpenExternalApplication.java:19)
Caused by: java.io.IOException: CreateProcess error=740, The requested operation requires elevation
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:189)
at java.lang.ProcessImpl.start(ProcessImpl.java:133)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
... 4 more
谁能建议我怎么做?
解决方法:
Java(或者可能是直接使用CreateProcess系统调用的任何其他进程)对于需要访问提升的可执行文件并不好.
您可以通过shell执行程序来解决这个问题:
String command = "C:\\setup.exe";
Runtime.getRuntime().exec("cmd /c "+command);
标签:runtime-exec,java,security,permissions 来源: https://codeday.me/bug/20190901/1782493.html