Thursday, May 22, 2014

How to Launch Several Programs with a Windows Batch Script

In the mornings whenever I need start programming on my computer (running Windows 8.1), I need to start quite a view (three...so not actually that many) programs so that I can program easily. It is just annoying to start the same three programs every morning just so that I can do my job.

Two days ago, I decided to use my computer programming prowess to build a Windows Batch Script that would launch the three programs for me automatically. This script I then added to my desktop and could launch with a simple double click.

HOW TO DO IT

The first thing that you need to do is create the script file. Windows Batch Script files have a .bat extension, so all you need to do is create a new file in Notepad and then Save As "LETSFUCKINGGO.bat", or really whatever you want to name your file. Make sure that you set the Save As Type (the very bottom select menu in the window) to "All Files (*.*)" from "Text Documents (*.txt)". This ensures that you can use your own file extension when saving the document. If you don't do this step then your file will be saved as "LETSFUCKINGGO.bat.txt", which will not run as a Windows Batch Script.

Now that you have saved your file, you should have a window that looks like:

Batch Scripts have a command start that is used to run a file at a given location. The syntax is then "start C:\path\to\my\program\program.exe" to run a program at any file location on your computer. So you could run several start statements in a row to start several programs. However, if you just do this, you will be left with an empty command prompt window for every program that you opened with the script. What we have now:

We could add the exit command after every start call, but then we would have to have as many exit calls as we had start calls. It's a solution, but a messy one. So what I find a far cleaner solution is to use the following syntax: "start "window-name" "C:\Path\To\The\File\program.exe" to launch the programs. Then if you specify a blank window name, the programs should all be launched from the same thread, which should terminate after the programs have all been launched. Therefore the window should look like this:


One additional thing. I use one program in the morning that is actually only launched through a custom shortcut that actually launches several things in order to properly finally launch the correct  process. So, if I just link to the program that is eventually launched, it won't have been initialized properly, and it is totally useless to me in that state, therefore, I need to start the shortcut that initializes the program. To do that, I just specify the name of the shortcut + ".lnk". So my final script looks something like this: 


This final save has a comment at the top to specify what this script does, and then a little echo call that prints out the specified text (for fun).

I hope this has helped. Enjoy, and have a fun and speedy program startup.

Food for thought, my friends.
 ~V 1.1~

No comments:

Post a Comment