Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 726
Muzy Avatar asked May 30 '12 06:05

Muzy


People also ask

Can I pass the password to the runas command?

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).

How do you use runas commands?

To use runas at the command line, open a command prompt, type runas with the appropriate parameters, and then press ENTER.


1 Answers

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".

like image 74
user2286013 Avatar answered Oct 03 '22 02:10

user2286013