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.
The runas command does not allow a password on its command line. This is by design (and also the reason you cannot pipe a password to it as input).
To use runas at the command line, open a command prompt, type runas with the appropriate parameters, and then press ENTER.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With