Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching .exe in its own directory with elevation priviledges

My question is pretty simple, I would like to launch a .exe in its own directory but with elevation rights/privileges. I know that this question as been raised before but I didn't found the right way for fixing my problem.


Indeed, I first tried this :

String workingDir = "C:\\TEST\\";
String cmd = workingDir + "game.exe";
Runtime.getRuntime().exec(cmd,null,new File(workingDir));

I got the following error:

CreateProcess error=740, The requested operation requires elevation

Then I tried this:

ProcessBuilder builder = new ProcessBuilder(
    new String[] {"cmd.exe", "/C","C:\\TEST\\game.exe"});
Process newProcess = builder.start();

And it runs but not in its own directory. How can I fix this please?

like image 796
user1633807 Avatar asked Oct 07 '22 19:10

user1633807


1 Answers

I wonder if this will work:

String workingDir = "C:\\TEST\\";
ProcessBuilder builder = new ProcessBuilder(
    new String[] {"cmd.exe", "/C",workingDir+"game.exe"}
  );
builder.directory(new File(workingDir));
Process newProcess = builder.start();
like image 146
Mike Tunnicliffe Avatar answered Oct 10 '22 02:10

Mike Tunnicliffe