How to run Windows OS cmd.exe multiple commands one after another, I use ncrack, commands
I manually open cmd.exe and I paste this code:
ncrack --user Admin -P pass1.txt <IPAddress>:3389 -oN good.txt -f When pass1.txt is finished I paste manually to cmd.exe the second command, which contains the Pass2.txt etc...:
ncrack --user Admin -P pass2.txt <IPAddress>:3389 -oN good.txt -f then I paste manually to cmd, Pass.3txt
ncrack --user Admin -P pass3.txt <IPAddress>:3389 -oN good.txt -f How can I run all commands automatically in a batch file, one after another and not all at the same time?
55 Answers
Run multiple commands one after another in cmd
Try using the conditional execution & or the && between each command either with a copy and paste into the cmd.exe window or in a batch file.
Additionally, you can use the double pipe || symbols instead to only run the next command if the previous command failed.
Execute command2 after execution of command1 has finished
ncrack --user Admin -P pass1.txt <IPAddress>:3389 -oN good.txt -f & ncrack --user Admin -P pass2.txt <IPAddress>:3389 -oN good.txt -f & ncrack --user Admin -P pass3.txt <IPAddress>:3389 -oN good.txt -f Execute command2 only if execution of command1 has finished successfully
ncrack --user Admin -P pass1.txt <IPAddress>:3389 -oN good.txt -f && ncrack --user Admin -P pass2.txt <IPAddress>:3389 -oN good.txt -f && ncrack --user Admin -P pass3.txt <IPAddress>:3389 -oN good.txt -f Execute command2 only if execution of command1 has finished unsuccessfully
ncrack --user Admin -P pass1.txt <IPAddress>:3389 -oN good.txt -f || ncrack --user Admin -P pass2.txt <IPAddress>:3389 -oN good.txt -f || ncrack --user Admin -P pass3.txt <IPAddress>:3389 -oN good.txt -f Supporting Resources
0Use below syntax in your cmd file.
call command1 call command2 . . call commandx Example:
call mvn install:install-file -Dfile=spring.jar -DgroupId=com.td.tdi.creditProtection.webservice -DartifactId=spring -Dversion=1.0 -Dpackaging=jar call mvn install:install-file -Dfile=com.ibm.ws.prereq.jaxrs.jar -DgroupId=com.td.tdi.creditProtection.webservice -DartifactId=com.ibm.ws.prereq.jaxrs -Dversion=1.0 -Dpackaging=jar call mvn install:install-file -Dfile=com.ibm.ws.runtime.jar -DgroupId=com.td.tdi.creditProtection.webservice -DartifactId=com.ibm.ws.runtime -Dversion=1.0 -Dpackaging=jar call mvn install:install-file -Dfile=IMSConnection_Utilities.jar -DgroupId=com.td.tdi.creditProtection.webservice -DartifactId=IMSConnection_Utilities -Dversion=1.0 -Dpackaging=jar 1Just add all the commands line by line in a batch file, and save the file as somename.bat.
Execute that batch file; all the commands would run sequentially in the order of their presence in the file.
How to execute the batch file through cmd:
path/to/the/directory/of/your/batchfile/somename.bat 3You can enter both commands on the same line and separate them with either a single ampersand (which causes them to be run in sequence) or two ampersands (which introduces simple error checking: the second command only runs if the first one was successful)
e.g.:
ncrack --user Admin -P pass1.txt <IPAddress>:3389 -oN good.txt -f && ncrack --user Admin -P pass2.txt <IPAddress>:3389 -oN good.txt -f 3All I did was paste the commands. For instance, to better my Internet connection I pasted:
ipconfig /flushdns ipconfig /registerdns ipconfig /release ipconfig /renew netsh int ip reset netsh winsock reset Press the right click on your mouse, and whether on cmd or powershell it automatically executes all of them in sequence. You don't even have to press 'enter'. Simple! (the last one i.e 'netsh winsock reset'was the only one I had to press enter for as it did not run automatically)