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();
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");
除了@aleroot的答案,您还应该使用ProcessBuilder而不是Runtime.exec
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.