我必须通过CMD命令以管理员优先级打开CMD。所以我尝试这个代码然后它要求输入密码,但我如何在同一个过程中提供密码。然后我必须赶上新开的CMD。
Process p = Runtime.getRuntime().exec("runas /noprofile /user:Partha >fg.txt")
p.waitFor();
p=Runtime.getRuntime().exec("password");
p.waitFor();
答案 0 :(得分:2)
您最好使用允许传递密码作为参数的PsExec util:
psexec \\computername -u domain\user -p password
否则你可以尝试将密码作为STDIN:
传递Runtime.getRuntime().exec("cmd /C echo YOUR_PASS | runas /noprofile /user:Partha >fg.txt");
答案 1 :(得分:2)
除了@ aleroot的回答,你应该使用ProcessBuilder而不是Runtime.exec