0

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();
1
  • 1
    Please post the code as text in your question, do not attach it as an image. Commented Nov 13, 2015 at 8:19

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

Comments

2

in addition to @aleroot's answer, you should use ProcessBuilder rather than Runtime.exec

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.