Tips and tricks creating batch files
Start with the basics of BAT
A batch file is a text file that stores commands executed by the command interpreter. It is usually used to simplify the execution of many commands for a given task. When the batch file is launched (by double-clicking on a file stored in Windows Explorer), the shell program (command.com or cmd.exe) reads the file and executes commands one line at a time. Batch files usually have the extension.BAT (for all versions of Windows) or .CMD (Windows NT).
When will you use the batch file? Whenever you need to open several programs for this task. For example, when it comes time to pay monthly bills, you usually open a browser to access online banking, open a spreadsheet for tracking payments, and a Calc calculator program. One batch file can easily open all three with a single click. In it, you will create the following commands:
NOTE. The following examples and file paths apply to Windows 7. The XP paths may differ for some programs, as well as for MS Office (Office 2007 is used in the example below) on your computer. In addition, due to the fact that some sites do not allow the use of backslashes, the following examples use a slash for paths to folders. When creating your batch files, use a backslash in the path to the folder.
start I d C: I Windows I System32 calc.exe
start I d "C: I Program Files I Mozilla Firefox" firefox.exe
start I d C: I finance I spreadsheets budget.xls
When creating a batch file, use the Notepad program (or any other text editor) and save it with the BAT extension (rather than the default.TXT extension).
Let's quickly review each of the above commands. First, the "Start" command tells Windows to open a
separate window in which the program runs. Secondly, I d is called a switch and instructs Windows to read the following information in the form of a file or a command path for searching the program. If there are spaces in the path, the full path must be placed in double quotes.
Thirdly, the name of the executable file is added, including its extension. And fourthly, if there is a file or URL that needs to be opened, then this is the place where it is located. For example, budget budget table. Xls. The above example is a simple example. Batch files can handle more complex tasks. The following is an example of a complex batch file
The above example is a simple example. Batch files can handle more complex tasks. The following is an example of a complex batch file for setting up a simple shutdown sequence.
title Conditional termination
set I p name = enter name:
echo Hello,% name%
echo 1. Shutdown
set I p choice = enter your choice 1,2:
if% choice% == 1 goto shutdown
if% choice% == 2 output
set I p sec = Enter the number of seconds that the computer will be turned off:
set I p msg = enter the disconnect message you want to display:
shutdown -s -f -t% sec% -c "% msg%"
echo-off started at% time%
set I p cancel = type cancel to stop off
if% cancel% == cancel shutdown -a
if% cancel% == cancel goto start
Depending on your needs, the internet is full of helpful file command that create a diverse range of duties your computer can achieve in a few short batch file commands. Interestingly enough, smartphones are quickly following this task if you own an Android model. Task commands can further be modified and greatly improve the usage of your phone moreover.