I\'m trying to run an external executable, but apparently it needs elevation. The code is this, modified from an example of using ProcessBuilder (hence the array with one a
Prunge's answer works fine for me.But after doing a bit more research ,I found out another approach using vb script and batch file.I prefer this approach because using vb-script does not cause black cmd window to pop up every time,when I open my application.
Create an ordinary bat file to open the external executable file. I am going to open a MySQL server executable file
@echo off
cd "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin"
:: Title not needed:
start /MIN mysqld.exe
exit
Save it as mysql.bat
Now create a vb script with admin privileges and at the end add script to open mysql.bat file.
At the end CreateObject("Wscript.Shell").Run runs the bat file mysql.bat.
Set WshShell = WScript.CreateObject("WScript.Shell")'
If WScript.Arguments.length = 0 Then
Set ObjShell = CreateObject("Shell.Application")
ObjShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
Wscript.Quit
End if
CreateObject("Wscript.Shell").Run "C:\Users\Shersha\Documents\NetBeansProjects\Berries\batch\mysql.bat",0,True
Thats it
try {
Runtime.getRuntime().exec("wscript C:\\\\Users\\\\Shersha\\\\Documents\\\\NetBeansProjects\\\\Berries\\\\batch\\\\mysql_start.vbs");
} catch (IOException e) {
System.out.println(e);
System.exit(0);
}