Have to install a custom service (Which requires administrative privilege) through runtime command line process using java.
OS Windows 7
Seems, that couldn’t be done only with Java code but calling native commands through JNI.
The below code opens the command prompt as administrator but couldn’t execute the subsequent command in the same prompt with the privilege.
Process p = Runtime.getRuntime().exec("cmd /c start runas /user:domain\\administrator /savecred:try.txt cmd");
Is there any optimal way to achieve this?
thanks,
If you’re on a *nix system, you can use
sudofromRuntime.exec. See this question for details.