0

In my Windows Selenium Java project I am trying to run a AutoHotKey exe, but the execution of the exe needs to be done as admin. How would I run the following as admin?

Runtime.getRuntime().exec("C:\\Scripts\\selectFile-emailmsg.exe");

Thanks.

tt_time
  • 23
  • 4
  • `ProcessBuilder` much better. Check [this](https://stackoverflow.com/questions/18026393/read-stdout-of-runas-child-process-started-by-processbuilder-or-defaultexecuto) out – g00se Aug 03 '23 at 11:29
  • I tried ProcessBuilder but the exe wouldn't run. I ended up using, Runtime.getRuntime().exec("cmd runas /user:administrator /savecred /c start \"\" \"C:\\Scripts\\selectFile-open1jpg.exe\""); – tt_time Aug 07 '23 at 13:52

1 Answers1

0
Runtime.getRuntime().exec("cmd runas /user:administrator /savecred /c start \"\" \"C:\\Scripts\\selectFile-open1jpg.exe\"");
Abra
  • 19,142
  • 7
  • 29
  • 41
tt_time
  • 23
  • 4
  • 1
    check the [documentation](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/Runtime.html#exec(java.lang.String)) of that method: "**Deprecated.** This method is error-prone and should not be used, the corresponding method [`exec(String[])`](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/Runtime.html#exec(java.lang.String%5B%5D)) or [`ProcessBuilder`](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/ProcessBuilder.html) should be used instead. ..." – user16320675 Aug 07 '23 at 14:29