Take the 2-minute tour ×

I am developing an java application from which I have to run xyz_setup.exe installer. I tried the following code

String command = "C:\\xyz_setup.exe"; 

But it was throwing the following error

java.io.IOException: Cannot run program "C:\Users\NewtonApples\Downloads\idman614.exe": CreateProcess error=740, The requested operation requires elevation
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    at java.lang.Runtime.exec(Runtime.java:615)
    at java.lang.Runtime.exec(Runtime.java:448)
    at java.lang.Runtime.exec(Runtime.java:345)
    at upendra.OpenExternalApplication.main(OpenExternalApplication.java:19)
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:189)
    at java.lang.ProcessImpl.start(ProcessImpl.java:133)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
    ... 4 more

Can any one suggest me how to do this?

share|improve this question
Possible duplicate of stackoverflow.com/questions/1385866/java-run-as-administrator –  madhairsilence Jan 18 '13 at 5:38
@madhairsilence as Java developer, you don't always have control over executable (such as java.exe) which runs your code - often doing manifest etc is not an option. This is legitimate problem, and one possible solution to it is to run the program via cmd, which knows how to request privilege elevation. He's not asking to elevate current process - he only wants to run elevated setup, which is a different problem, so this is not a duplicate. –  Cozzamara Jan 18 '13 at 5:50
add comment

2 Answers

up vote 4 down vote accepted

Java (or likely any other process which uses CreateProcess system call directly) is not good with executables requiring access elevation. You can get around that by executing your program via shell:

  String command = "C:\\setup.exe";
share|improve this answer
This is running perfectly but when the executable file is in following location it was showing an error. Path: E:\\New folder\\Setup.exe –  upendra Jan 18 '13 at 17:30
That's because you have space in folder name - enclose it in double quotes: Runtime.getRuntime().exec("cmd /c \"" + command + "\""); –  Cozzamara Jan 18 '13 at 18:30
Thank you. It's working fine. Is it possible to trace the progress of the installation. That means after completing the Setup.exe installation I have to display 'Successfully Completed Installation' message through java. Regard's –  upendra Jan 19 '13 at 4:35
But of course. Runtime.exec returns object of type Process. On that, you can do exitValue() to obtain exit code of your setup program. getOutputStream() and getErrorStream() will give you its standard output and standard error streams. To get all of that, you have to do Process.waitFor() first, of course, to wait for it to finish. Non-zero exit code most likely indicates failure, but check your specific setup. –  Cozzamara Jan 19 '13 at 5:33
Thanks a lot... Everything is working fine. –  upendra Jan 19 '13 at 10:12
add comment
import java.io.*; 
public class runExe{ 
Runtime run = Runtime.getRuntime(); 
Process pp=run.exec("D:/songs/VLC/vlc"); 
share|improve this answer
add comment

Your Answer


