19

I have a web applet that I update regularly and I finally decided to make an updater. However when I download an update in java it downloads fine. However when I try to unpack + run the update by using Runtime.getRuntime().exec(pathToFile); I get CreateProcess error=740, The requested operation requires elevation

How can I fix this if the program is a web applet? I can't just tell them to run their browsers as administrators. How can i fix this?

Kyle
  • 3,004
  • 15
  • 52
  • 79
  • Win32 executable a windows application – Kyle May 02 '11 at 04:50
  • One of my friends was having this exact same problem about a month ago (he was unrolling an update via a .exe file), and I remember that this link helped him tremendously: https://web.archive.org/web/20120619232416/https://mark.koli.ch/2009/12/uac-prompt-from-java-createprocess-error740-the-requested-operation-requires-elevation.html – Vinay May 02 '11 at 04:50
  • After a few days around this, i implemented a way to execute a program with arguments using "cmd /c" and executing the command "start" https://ss64.com/nt/start.html – marcolopes May 04 '23 at 12:11

7 Answers7

34

When using .exec(cmd), prefix your command with cmd /c so you end up with something like rt.exec("cmd /c <your command>"). This will launch the process and invoke the UAC if needed.

JJJ
  • 32,902
  • 20
  • 89
  • 102
Doug
  • 381
  • 3
  • 3
2

One Manual work around one of our engineers found, if it is not your application, start a cmd prompt, right click on the window and click the "Run as Administrator" menu item. in my case running the .jnlp file work!

2

I've faced such problem too when tried to run app with command:

cmd /c start <exe_file>

This command could not run executable that require Admin access. Instead use of

rundll32 url.dll,FileProtocolHandler <exe_file>

command solved my problem. This command triggers UAC prompt, so user could provide correct access before app will be launched.

In my app I used PrecessBuilder::start() function. This function returns java.lang.Process instance which will be alive (process.isAlive() == true) until user will handle UAC prompt, so it's better to add some loop to wait until it happens to consider for sure that app is launched.

alaptiko
  • 499
  • 3
  • 14
1

Reason:

When you try to run your application, your IDE attempts to start adb but it ends up getting 740 process error or adb down because your IDE is not allowed to run an adb.exe file from your platform tools in your sdk folder.

Solution:

  1. Kill adb.exe, kill eclipse.exe from task manager in windows.
  2. Close eclipse and disconnects your phone and restart it and disable USB debugging and enable it again.
  3. Go to eclipse icon right click and choose run as administrator
  4. Connect it to your device and run your application.

A golden tip - always run your eclipse,sdk manager,command prompt as administrator so your system gives full permission to specific application.

tested on window 7 64bit

device Samsung 4.4 eclipse ide

demongolem
  • 9,474
  • 36
  • 90
  • 105
user3626630
  • 104
  • 3
0

I had the same issue, resolve it by running the java application as an administrator, to make it permanent: Right click on your application , go to property > Compatibility > check "Run this program as an administrator"

(I have a batch file runs Java.exe -jar ....)

Behrangs
  • 19
  • 2
0

I've also faced this problem, But when tried to run Runtime.getRuntime().exec(filepath) with prefix "cmd /c " to the file path it worked perfectly

Your code should like Runtime.getRuntime().exec("cmd /c <filepath>")

Note: filepath-the complete directory list required to locate the file

in my code:

     String filepath="C:\\Users\\MSI\\Downloads\\AutomationInstaller.exe"
-1

If you problem is with Android Studio then killing any instance of adb.exe solves.