17

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?

  • 1
    This question is upvoted and has upvoted answers, few people found it helpful. Please don't spoil it. – Kamil Maciorowski Sep 19 '17 at 6:49
  • 2
    Why are you trying to delete this question and answers? Is it because it uses ncrack as example? Because ncrack targets particular IP? If so, the right thing to do is to change the example command, not to nuke the entire question. If you tell us your reasons we may work something out. – Kamil Maciorowski Sep 19 '17 at 8:56
  • 1
    I replaced the actual IP address with <IPAddress> in case that is your concern as well. – Pimp Juice IT Sep 19 '17 at 11:26
24

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

4

Just 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
  • 1
    @MunteanCosminManim - They would be running one after another, not at the same time. I hope this is what you want. – Am_I_Helpful May 21 '16 at 19:47
  • @MunteanCosminManim Yes, this is how a batch file works. It executes a command and waits until the command is finished, then runs the next command. In order to execute a command and immediately continue to the next, you'll have to use the command call or start too. – LPChip May 21 '16 at 20:57
4

Use 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
  • I mean ... that's exactly is the command I am trying to run multiple times – Firas Al Mannaa Oct 24 at 16:15
2

You 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

Source

  • I see JUICED_IT beat me to posting this solution :) – James Dearing May 21 '16 at 21:06
  • 1
    @MunteanCosminManim Changing your requirements after you've received answers is inappropriate, as it invalidates the answers you've already received. – DavidPostill May 22 '16 at 8:21
  • is not legal i ask to delete it plz – user466755 Sep 19 '17 at 7:15
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy