Help writting and running a batch file.

Discussion in 'Application Software' started by jetjock, May 1, 2010.

  1. jetjock

    jetjock MDL Senior Member

    Mar 6, 2010
    302
    17
    10
    I would like to place a batch file on my desktop that will execute two .exe files in succession. Files are both in the same folder. Would someone be kind enough to give me a batch file that will do this in Win 7?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. sam3971

    sam3971 MDL Guru

    Nov 14, 2008
    2,235
    311
    90
    dude, you need to know what folder that you want to execute the 2 programs. Here is a breakdown of it though. Lets say they are in just the C:\ Root, here are some commands that would get you going:

    "C:\1.exe" = First EXE
    "C:\2.exe" = Second EXE

    That is basically how it is done but you have to change the directory and file name accordingly.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. jetjock

    jetjock MDL Senior Member

    Mar 6, 2010
    302
    17
    10
    Thanks, I knew that much. I just didn't know if there was anything I had to put in to actually "Run" the .exe files. I assume I also have to add an "End" to terminate the batch, right?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. sam3971

    sam3971 MDL Guru

    Nov 14, 2008
    2,235
    311
    90
    #4 sam3971, May 1, 2010
    Last edited by a moderator: Apr 20, 2017
    you can actually end the programs withing the same batch script.

    It is Taskkill /IM "XXX.exe"

    the "X" stands for the name of the exe and if you have the batch file inside the same location where the exe's are then you only have to have something like this.

    Code:
    cd %0\..\
    start 1.exe
    start 2.exe
    taskkill 1.exe
    taskkill 2.exe
    Basically without having to have the location directory in the script. You must have the "cd %0\..\" in it at the top though for it to work right dude. :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. jetjock

    jetjock MDL Senior Member

    Mar 6, 2010
    302
    17
    10
    #5 jetjock, May 2, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I guess I should have just given the files I wanted to run in the first place 'cause what I'm doing ain't working! Here goes: C:\Program Files\Timbuktu Pro\tb2start.exe and C:\Program Files\Timbuktu Pro\tb2pro.exe are the two files I need to run consecutively with a batch file. Don't ask me why both have to run to start the program: I don't know! For some reason the last file will not start the program without the first running. If you can help me sam3971, I'd really appreciate it. :worthy:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
  7. jetjock

    jetjock MDL Senior Member

    Mar 6, 2010
    302
    17
    10
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    O yea dah...lol Thought you had more to post...lol
     
  9. sam3971

    sam3971 MDL Guru

    Nov 14, 2008
    2,235
    311
    90
    #9 sam3971, May 2, 2010
    Last edited by a moderator: Apr 20, 2017
    Ok then this is how you do it:
    Method 1: IF you want to call the files from outside the Timbuktu Pro folder:
    Code:
    "C:\Program Files\Timbuktu Pro\tb2start.exe"
    "C:\Program Files\Timbuktu Pro\tb2pro.exe"
    Method 2 Inside the Tumbuktu Pro folder:
    Code:
    cd %0\..\
    start tb2start.exe
    start tb2pro.exe
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. jetjock

    jetjock MDL Senior Member

    Mar 6, 2010
    302
    17
    10
    #10 jetjock, May 2, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    OK, that got it! I was missing the (")'s around the command lines. Do you have any idea how to get the "cmd.exe" box that opens with the program to close? I can just click on the "X" at the top right corner, or it will close when I shut the program down, but I'd like to add something to the batch file that will close it automatically after the program starts. I've tried adding "EXIT" and :END to the batch file, but neither worked.

    Thanks again for all your help. Folks in this forum (timesurfer notwithstanding) are really great! :worthy:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. sam3971

    sam3971 MDL Guru

    Nov 14, 2008
    2,235
    311
    90
    #11 sam3971, May 2, 2010
    Last edited by a moderator: Apr 20, 2017
    yea you type "Exit" in the bottom of the script so like lets say you use method 2, it would look like this:

    Code:
    cd %0\..\
    start tb2start.exe
    start tb2pro.exe
    exit
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. jetjock

    jetjock MDL Senior Member

    Mar 6, 2010
    302
    17
    10
    #12 jetjock, May 2, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    "Exit" (in quotes) will work, but only if the program is already running in the Start Bar. Batch will then open the control console and close the cmd window, but not if it's shut down completely. Not a big deal as the window can be closed manually; just wanted to try closing it with the batch. Many thanks for all your help.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. sam3971

    sam3971 MDL Guru

    Nov 14, 2008
    2,235
    311
    90
    dude, exit will close CMD down without the other programs. Isn't that what you want? Don't actually put the "" in it on the script.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. rjc862003

    rjc862003 MDL Junior Member

    Sep 4, 2009
    78
    12
    0
    #14 rjc862003, May 3, 2010
    Last edited: May 3, 2010
    sigh it seems batch files are becomeing a lost art anyway here is the proper way
    copy and paste in between the line
    -----------------------------------------------
    @echo off
    cd C:\Program Files\Timbuktu Pro
    start tb2start.exe
    start tb2pro.exe

    @ping 127.0.0.1 -n 2 -w 5000 > nul

    taskill /IM cmd.exe
    ---------------------------------------------------------
     
  15. Smorgan

    Smorgan Glitcher

    Mar 25, 2010
    1,855
    1,051
    60
    A sad truth except I use Batch files for my primary programming stuff lol...
     
  16. wulai

    wulai MDL Novice

    Mar 24, 2011
    5
    0
    0
    try using this:

    "C:\Program Files\Timbuktu Pro\tb2start.exe"
    "C:\Program Files\Timbuktu Pro\tb2pro.exe"
    pause.
     
  17. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,589
    340
    Why bumping up such an old thread???
     
  18. microjunk

    microjunk MDL Novice

    Oct 20, 2009
    26
    2
    0
    Has been awhile since coming here saw this thread and thought maybe a chance to help.

    I had a similar task I wanted to do in a batch file and this helped.....

    @echo off
    cls
    Start /w

    start your batch like this add the file path and the exe and any switches

    this will run the first program and when its finished it will start the second as long as start /w is in front of it.

    this works in vista and windows 7