开发者

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. 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;
imp开发者_C百科ort 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". 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..


I'm guessing you are using windows 7, when you run your batch process to start your JFileChooser test, right click and select "run as administrator".


The requested operation requires elevation

You do not have the rights to execute this setup. Probably UAC blocks it.

Use the runas command with Runtime#exec in Java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜