2

I tried this java code, in this code i move a file from from one directory to another one, then execute the file. I am using Windows 7 OS.

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

While i execute this i got "740: The requested operation requires elevation " error , if any possibilities to resolve it.

Aerrow
  • 12,086
  • 10
  • 56
  • 90

2 Answers2

1

Short answer is that you can't do it in-process. You need to launch a new process that is elevated at the command line. (see the elevate command).

Please see this question and answer here - they address your issue.

Community
  • 1
  • 1
hawkeye
  • 34,745
  • 30
  • 150
  • 304
0

Service host local system network restricted 10

HKEY_LOCAL_MACHINE > SYSTEM > ControlSet001

registry value named Start in the right hand panel and double click on it.

Link