I have to open a CMD with administrator previlege by CMD command . 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.
Process p = Runtime.getRuntime().exec("runas /noprofile /user:Partha >fg.txt")
p.waitFor();
p=Runtime.getRuntime().exec("password");
p.waitFor();
Chris Dennett
22.8k8 gold badges61 silver badges85 bronze badges
-
1Please post the code as text in your question, do not attach it as an image.EkcenierK– EkcenierK2015年11月13日 08:19:28 +00:00Commented Nov 13, 2015 at 8:19
2 Answers 2
You could better use PsExec util that allow to pass the password as argument :
psexec \\computername -u domain\user -p password
Otherwise you could just try passing the password as STDIN :
Runtime.getRuntime().exec("cmd /C echo YOUR_PASS | runas /noprofile /user:Partha >fg.txt");
answered Nov 13, 2015 at 8:24
aleroot
73k32 gold badges182 silver badges220 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
in addition to @aleroot's answer, you should use ProcessBuilder rather than Runtime.exec
answered Nov 13, 2015 at 8:30
jwenting
5,6593 gold badges28 silver badges33 bronze badges
Comments
lang-java