I want to execute a command from a Java-application using
Runtime.getRuntime.exec(command);
but the command need Admin-privileges. If I use
runas /user:Administrator "cmdName parameters"
nothing happens because I need to give user und pw as parameter to the command. But I need to run a command to the cmd, so that a new cmd.exe starts as administrator and asks if I want to run cmd.exe as admin. After agree the command should be run in the admin-cmd. So like this:
String command = "popupNewCmdAsAdminAndRun "batWhichNeedsAdmin.bat" "
Runtime.getRuntime.exec(command);
Has anyone an Idea? Thanks in advance!
You can open cmd as an administrator by searching for it in the Windows search bar located in the bottom left corner of the desktop screen. Then, right-click on Command Prompt and select Run as administrator.
Executing a Command from String Process process = Runtime. getRuntime(). exec("ping www.stackabuse.com"); Running this code will execute the command we've supplied in String format.
you should do the following
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "command";
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit(60000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With