Running .exe in its own directory with elevation privileges

My question is quite simple, I would like to run .exe in my own directory, but with rights / privileges. I know this question was raised earlier, but I did not find the right way to fix my problem.


In fact, 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 starts, but not in its own directory. How can i fix this?

+5
source share
4 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();
+1
source

It seems you want to install

builder.directory(new File("C:\\TEST"));

which are

Sets the process link working directory


, .

https://www.google.co.uk/search?q=CreateProcess+error%3D740%2C+The+requested+operation+requires+elevation

+1

I do not think that it is possible to increase the privileges of a forked process. You must start a new process with an account that has the rights that you need.

+1
source

Perhaps create a batch file with cd and the command you want to run, then execute the batch file with cmd.

+1
source

All Articles