java - 740 : The requested operation requires elevation in java

标签 java windows-7

我尝试了这个java代码,在这个代码中我将文件从一个目录移动到另一个目录, 然后执行该文件。我使用的是 Windows 7 操作系统。

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

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


import org.apache.commons.io.FileUtils;
import org.omg.CORBA.Environment;

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

        try {
            FileUtils.copyFileToDirectory(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("runas /user:FSSD test/setup.exe");   
            //Process p= rt.exec("test/setup.exe");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
  }
}

当我执行此操作时,我收到“740:请求的操作需要提升”错误,如果有可能解决它。

最佳答案

简短的回答是你不能在进程中执行此操作。您需要启动一个在命令行提升的新进程。 (参见提升命令)。

请参阅此问题和答案 here - 他们解决你的问题。

关于java - 740 : The requested operation requires elevation in java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7120533/

相关文章:

java - 如何复制二维字符串数组?

java - 分配给通过 Java 调用的命令行程序的内存

java - 使用 inputMap 过滤列表(List1)中的数据(键和值可能因每个请求而异)

.net - Windows 7中的“调试程序”选项

C++ - 使控制台全屏显示?

excel - dde excel 2010 链接不起作用

java - 碰撞检测无法正常工作

java - 如何使 Immutables 库跳过序列化可选字段

windows-7 - 在虚拟电脑上测试IE9

git - TortoiseGit 和 Pageant,每次都必须为 "add key"