exe没有运行

时间:2011-08-18 12:31:56

标签: java file runtime.exec

我使用以下Java代码将文件从一个目录移动到另一个目录,然后在目标目录中执行该文件。我的代码是

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();
        }
  }
}

当我执行此代码时,通过执行此代码成功移动了文件,我收到了以下错误。

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

我在这里用“setup.exe”。它是一个可执行文件。当我在运行时执行时,我得到了上述错误。为什么会发生这种情况,有可能解决它。提前谢谢..

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

  

请求的操作需要提升

您无权执行此设置。可能UAC阻止了它。

在Java中使用runas命令和Runtime#exec

相关问题