简体   繁体   English

exe无法运行

[英]The exe doesn't run

I used the following Java code for move the file form one directory to another, then execute the file in the destination directory. 我使用以下Java代码将文件从一个目录移动到另一个目录,然后在目标目录中执行文件。 My code is 我的代码是

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;


import org.apache.commons.io.FileUtils;
public class JFileChooserTest {
  public static void main(String[] args) {
        String filelocation="C:\\Users\\FSSD\\Desktop\\OutPut\\Target";
        File trgDir = new File(filelocation);
        System.err
                .println("file location>>>>>>>>>>>>>>>>>>>"
                        + filelocation);
        File desDir = new File(
                "C:\\Users\\FSSD\\IndigoWorkSpace\\Swing\\test");

        try {
            FileUtils.copyDirectory(trgDir, desDir);
            // FileUtils.copyDirectory(srcDir, trgDir);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        Runtime rt=Runtime.getRuntime();
        try {
            Process p=rt.exec("test\\setup.exe");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
  }
}

While i executing this code, the file was successfully moved by i execute this code i got the following error. 当我执行此代码时,文件被我执行此代码成功移动,出现以下错误。

java.io.IOException: Cannot run program "test\setup.exe": CreateProcess error=740, The requested operation requires elevation
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at java.lang.Runtime.exec(Runtime.java:328)
    at JFileChooserTest.main(JFileChooserTest.java:34)
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:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
    ... 4 more

Here i used "setup.exe" . 在这里,我使用了“ setup.exe” It is an executable file. 它是一个可执行文件。 while i execute at run time i got the above error. 当我在运行时执行时,出现上述错误。 Why it will happens, is any possible to resolve it. 为什么会发生,有可能解决它。 Thanks in advance.. 提前致谢..

我猜您正在使用Windows 7,当您运行批处理过程以启动JFileChooser测试时,右键单击并选择“以管理员身份运行”。

The requested operation requires elevation 请求的操作需要提升

You do not have the rights to execute this setup. 您无权执行此设置。 Probably UAC blocks it. 可能是UAC阻止了它。

Use the runas command with Runtime#exec in Java. 在Java中将runas命令与Runtime#exec一起使用。

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

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