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

前端 未结 3 671
无人共我
无人共我 2021-02-13 15:03

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 \         


        
相关标签:
3条回答
  • 2021-02-13 15:20

    when i was kid a did this

    echo Pa$$W0Rd | some_command_expects_it
    
    0 讨论(0)
  • 2021-02-13 15:24

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

    0 讨论(0)
  • 2021-02-13 15:27

    Try this

    runtime.getruntime().exec("cmd /C echo YOUR_PASS | runas /user:Admin \"C:\Program Files\test.bat\"");
    
    0 讨论(0)
提交回复
热议问题