简体   繁体   English

如何使用java运行setup.exe文件

[英]How to run setup.exe file using java

I am developing an java application from which I have to run xyz_setup.exe installer. 我正在开发一个java应用程序,我必须从中运行xyz_setup.exe安装程序。 I tried the following code 我尝试了以下代码

String command = "C:\\xyz_setup.exe"; 
Runtime.getRuntime().exec(command);`

But it was throwing the following error 但它抛出了以下错误

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

Can any one suggest me how to do this? 谁能建议我怎么做?

Java (or likely any other process which uses CreateProcess system call directly) is not good with executables requiring access elevation. Java(或者可能是直接使用CreateProcess系统调用的任何其他进程)对于需要访问提升的可执行文件并不好。 You can get around that by executing your program via shell: 您可以通过shell执行程序来解决这个问题:

  String command = "C:\\setup.exe";
  Runtime.getRuntime().exec("cmd /c "+command);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM