Tips related to

Tuesday, 13 July 2010

How To Create A Batch File

That batch file works great if you want the same applications to always open at once.For example, you have a book report due and you need to research the material on the Internet. In this case you want to open Microsoft Word and Firefox.To do this we can create a batch file with a list of applications. When you run the batch file, a menu will appear that will accept user input from the command line and open the applications that you choosen.

To create the batch file, first, you will want to make a list of applications that you use frequently.

For this example, I will select six applications (remember they can be any amount and type of applications you want to use):

Notepad
Calculator
Microsoft Word
Microsoft Excel
Internet Explorer
Firefox

Next, find the executable path for each application. This can be accomplished by finding the shortcut of the application in the Start Menu and right click on the application icon "make sure the Shortcut tab is selected".


For Microsoft Office Applications, you will need to look in the folder where Office is installed. On my computer, the executable path is:

C:\Program Files\Microsoft Office\Office12 EXCEL.EXE
NOTE: Your path may be different depending on the version of Windows and Office you are using.

For any application executable that you can not find, use Windows search (in XP and Vista) to help find the location.

Create The Batch File

Just right click on your desktop and select New \ TextDocument.

Next name the file what ever you want and for now, leave the extension as .txt (I have named my file chooseapp.txt).

Open the file that you created using notepad, then copy and paste the following code. An explanation of the code as follow:

@echo off
cls
:start
echo.
echo 1. Notepad
echo 2. Calculator
echo 3. Microsoft Word
echo 4. Microsoft Excel
echo 5. Internet Explorer
echo 6. Firefox
echo 7. I'm Done
echo.
echo.
set /p x=Pick:
IF '%x%' == '%x%' GOTO Item_%x%

:Item_1
start /MIN /DC:\Windows\System32 notepad.exe
GOTO Start

:Item_2
start /MIN /DC:\Windows\System32 calc.exe
GOTO Start

:Item_3
start /MIN /D"C:\Program Files\Microsoft Office\Office10" WINWORD.EXE
GOTO Start

:Item_4
start /MIN /D"C:\Program Files\Microsoft Office\Office10" EXCEL.EXE
GOTO Start

:Item_5
start /MIN /D"C:\Program Files\Internet Explorer\iexplore.exe"
rudra ki dunia
GOTO Start

:Item_6
start /MIN /D"C:\Program Files\Mozilla Firefox" firefox.exe rudra ki dunia
GOTO Start

:Item_7
exit

How The Batch File Works

- The @echo off prevents displaying results of the commands at the prompt.

cls – clears the screen

:start – begins the commands to display the list

echo. – creates a blank line

echo 1. Notepad
echo 2. Calculator
echo 3. Microsoft Word
echo 4. Microsoft Excel
echo 5. Internet Explorer
echo 6. Firefox
echo 7. I'm Done


The above lines are the applications that will be displayed in the list. You should edited these lines with the names of the applications you want displayed.

set /p x=Pick: – set the variable name x=Pick that is used in the next line

IF '%x%' == '%x%' GOTO Item_%x% – statement that determines what number in the list you chose and to go to the line (GOTO) that will open the application.

—>>>The above two lines should not be edited<<<—

:Item_1
start /MIN /DC:\Windows\System32 notepad.exe
GOTO Start


All lines starting with :Item_ and their number (in my example 1 to 6) is where you enter the path and executable name of the application to be opened.

The start command has two parts:

MIN will minimize the application when it is opened (NOTE: some applications will ignore this and NOT open minimized).

/DC:\Windows\System32 notepad.exe is where you enter the path and executable name. You will need to edit this parameter with the application you want opened.

GOTO Start – tells the batch file to return to the Start line in the beginning that will allow you to make another selection.

:Item_7
exit


The above lines ends the batch file when you select option 7. Depending on the number of applications in YOUR list, make sure to re-number the list including the last item that is used to exit the batch file.

When finished, save the file and don't forget to rename the file (right click on the file and select rename) and use .bat as the extension.

Run The Batch File

To run it, double click on the batch file. A command window will appear allowing you to make your selections one at a time (it will loop) by entering the number next to the word Pick, then pressing the Enter key.



After making your selections, don't forget to select the last number in the list so the batch file will exit.

If you need to re-edit the batch file, just right click on it and select edit (don't double click to edit). After editing, save the file before closing.

As you can see, creating this batch file can be a handle little utility to have around. It can also be used to not only open applications, but files that you may use frequently

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | 100 Web Hosting