Muzy
Muzy

Reputation: 505

How to supply password to runas command when executing it from java

I have to run a batch files from a java program which need administrative privilege. I am using the below command

runtime.getruntime().exec("runas /user:Admin \"C:\\Program Files\\test.bat\"");

but when it get executed its prompt for the password for the Admin account. How can I give the password for it.

Upvotes: 14

Views: 67877

Answers (3)

yatul
yatul

Reputation: 1111

Try this

runtime.getruntime().exec("cmd /C echo YOUR_PASS | runas /user:Admin \"C:\Program Files\test.bat\"");

Upvotes: 2

user2286013
user2286013

Reputation: 121

You can't pipe a password into runas, as it requests the password from the terminal, not from stdin. There's no equivalent of "sudo -s".

Upvotes: 12

triclosan
triclosan

Reputation: 5714

when i was kid a did this

echo Pa$$W0Rd | some_command_expects_it

Upvotes: -1

Related Questions