[英]Command prompt In JAVA
I have to open a CMD with administrator previlege by CMD command . 我必须使用CMD命令以管理员权限打开CMD。 So i try this code and then It asks for password but how can i provide the password in the same process.
因此,我尝试此代码,然后要求输入密码,但我如何在同一过程中提供密码。 And then I have to catch the newly opened CMD.
然后我必须赶上新打开的CMD。
Process p = Runtime.getRuntime().exec("runas /noprofile /user:Partha >fg.txt")
p.waitFor();
p=Runtime.getRuntime().exec("password");
p.waitFor();
You could better use PsExec util that allow to pass the password as argument : 您最好使用允许将密码作为参数传递的PsExec util:
psexec \\computername -u domain\user -p password
Otherwise you could just try passing the password as STDIN : 否则,您可以尝试将密码作为STDIN传递:
Runtime.getRuntime().exec("cmd /C echo YOUR_PASS | runas /noprofile /user:Partha >fg.txt");
除了@aleroot的答案,您还应该使用ProcessBuilder而不是Runtime.exec
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.