0

I am trying to execute an exe file through Java code. I wrote below a simple code in Eclipse but got error. Tried multiple solutions but all in vain.

My code:

package com.runExeFile;

import java.io.File;

public class ClassA {

    public static void main(String[] args) throws Exception {
         Runtime.getRuntime().exec("C:\\FlashBuild\\14_09_2017_play_27_0_r0_137\\FF_32Release\\Something.exe");
    }

}

The Error I am getting:

Exception in thread "main" java.io.IOException: Cannot run program "C:\FlashBuild\14_09_2017_play_27_0_r0_137\FF_32Release\install_flash_player_27_plugin.exe": CreateProcess error=740, The requested operation requires elevation
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at com.runExeFile.ClassA.main(ClassA.java:9)
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>(Unknown Source)`enter code here`
    at java.lang.ProcessImpl.start(Unknown Source)
2

2 Answers 2

1

It is because you need to run the program as administrator. To run the program as administrator here is the code. Error 740 is because of that only. See these link

CreateProcess error=740, The requested operation requires elevation

Java: run as administrator

import java.io.IOException;

public class RunAsAdminExample {
    public static void main(String[] args) throws IOException {
        Process myappProcess = Runtime.getRuntime().exec("powershell.exe Start-Process notepad.exe -verb RunAs");
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Finally got success with below line of code but still i did not get how it works. Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+PathOfExe);
0

I had done it recently. and the way I did was

try {
    File fileDirectory = new File("C:/someDirectory");
    Runtime.getRuntime().exec(new String[]{"cmd","/C","start someRunnable.exe"}, null, fileDirectory);
} catch (IOException e) {
    e.printStackTrace();
}

Which you needed to specify the directory to run and the start Command prompt to run the executable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.