应用程序执行命令
Runtime.getRuntime.exec(command);
但该命令需要Admin-privileges.如果我使用
runas /user:Administrator "cmdName parameters"
没有任何反应,因为我需要将user und pw作为参数提供给命令.
但我需要向cmd运行一个命令,以便新的cmd.exe以管理员身份启动,并询问我是否要以管理员身份运行cmd.exe.同意后,命令应该在admin-cmd中运行.像这样:
String command = "popupNewCmdAsAdminAndRun "batWhichNeedsAdmin.bat" " Runtime.getRuntime.exec(command);
有谁有想法?
提前致谢!
Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = "command"; process.StartInfo.Verb = "runas"; process.Start(); process.WaitForExit(60000);
翻译自:https://stackoverflow.com/questions/19175691/java-execute-command-in-a-new-cmd-exe-as-administrator