I am trying to open a password protected Rar file with cmd and when it asks for a password I want it to automatically insert the password stored in a text file. How can I do that?
Asked
Active
Viewed 550 times
1 Answers
0
I suppose WinRAR has CLI for that stuff:
unrar x -p your_password your_rar_file.rar
Instead of your_password
you can read from the file:
unrar x -p 'cat /path/to/passwdfile' your_rar_file.rar

Raymond Reddington
- 1,709
- 1
- 13
- 21
-
Thank you @ZavenZareyan. I am using this in a for loop, is there a way to stop or break out of the loop when the password is correct? – Mans1 Mar 09 '20 at 12:35
-
You should go in this direction: https://stackoverflow.com/questions/2591758/batch-script-loop – Raymond Reddington Mar 09 '20 at 12:36
-
Thank you @ZavenZareyan. `for /F "tokens=*" %A in (myfile.txt) do UnRar x file.rar -p%A ` i am using this command and it works but the only problem is that even when it finds the correct password it continues to try other password and i want it to stop or break out of the loop when it finds the correct password, is there a simple way to do that? – Mans1 Mar 09 '20 at 12:46
-
Set variable, check it in every loop, stop if it is true. Similar example: https://stackoverflow.com/questions/1184408/exit-in-for-loop-windows-command-processor-cmd-exe – Raymond Reddington Mar 09 '20 at 12:56