我必须使用CMD命令以管理员权限打开CMD。因此,我尝试此代码,然后要求输入密码,但我如何在同一过程中提供密码。然后我必须赶上新打开的CMD。
Process p = Runtime.getRuntime().exec("runas /noprofile /user:Partha >fg.txt")
p.waitFor();
p=Runtime.getRuntime().exec("password");
p.waitFor();
最佳答案
您最好使用允许将密码作为参数传递的PsExec util:
psexec \\computername -u domain\user -p password
否则,您可以尝试将密码作为STDIN传递:
Runtime.getRuntime().exec("cmd /C echo YOUR_PASS | runas /noprofile /user:Partha >fg.txt");
关于java - 在JAVA中的命令提示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33688312/