Creating a Batch File


The Scheduled Task Wizard is great for having specific programs run at regular intervals without intervention, but most programs have specific parameters that you can set that change how the program is run. For example, if you run the defrag utility, you can include a -a parameter after the command to cause the utility to run in analysis mode only. Using these parameters, you can control more precisely the type of command that is run.

There are several ways to execute a program with the appropriate parameters attached, including entering the flags in the Run field of the Properties dialog box for the scheduled task, entering the command into the Start, Run dialog box or in the Command Prompt interface, or creating a separate batch file. This last method is particularly useful. By creating a batch file, you can define specific program commands or execute multiple commands at once.

Locating program parameters

Before you can use a program parameter, you need to find the specific parameters for the program that you plan to execute. You can often find these parameters within the Help file for the various utilities, as shown for the Defrag utility in Figure 39.14.

image from book
Figure 39.14: You can find parameters for a specific program within the Help file.

If you have the Command Prompt interface open, you can also get a program's parameters by typing the name of the program followed by the /? parameter. This retrieves a help list for the given program. You can open the Command Prompt interface with the Start image from book All Programs image from book Accessories image from book Command Prompt menu. Figure 39.15 shows the parameters for the Defrag utility.

image from book
Figure 39.15: You can view program parameters by typing the /? parameter after the program's name.

Entering parameters to a scheduled task

The easiest place to add parameters to a scheduled task is in the Properties dialog box for the selected scheduled task. You can simply add the appropriate parameter to the end of the execution command in the Run field, as shown in Figure 39.16.

image from book
Figure 39.16: You can add parameters to the end of the execution command in the Run field of the task's Properties dialog box.

Tip 

You can add multiple parameters to an execution command by separating them with a space.

Entering parameters into the Run dialog box

If you select the Start image from book Run menu, the Run dialog box, shown in Figure 39.17 opens. Using this dialog box you can enter a program to execute along with its parameters. It is important to have the exact program name typed correctly.

image from book
Figure 39.17: You can add parameters to the end of the execution command in the Run dialog box.

Using the Command Prompt interface

You can also execute program commands and parameters in the Command Prompt interface. This interface hearkens back to the DOS days when all instructions were run using text commands.

The Command Prompt interface opens using the Start image from book All Programs image from book Accessories image from book Command Prompt menu. You can enter DOS commands directly into the interface; you can get a list of DOS commands by entering the command help in the interface. You can perform all of these textual commands within Windows using the various utilities, but the textual commands are helpful when composing batch files.

Writing a batch file

Issuing program commands in the Run dialog box or the Command Prompt runs the command a single time only, but if you enter the commands into a text file and save them as a batch file that can be accessed as a scheduled task, then you have the power to run specific custom tasks regularly.

A batch file is simply a text file saved using the .bat file extension. These text files include any textual commands that can be entered in the Command Prompt interface, including program execution commands with parameters and any DOS textual commands. Once you've created the batch file, you can use the Scheduled Task Wizard to make the file into a scheduled task.

Tip 

Be sure to test your batch file before making it a scheduled task.

To create a batch file as a scheduled task, follow these steps:

  1. Select the Start image from book All Programs image from book Accessories image from book Notepad menu command to open Notepad.

  2. Enter the commands to execute in the Notepad window such as defrag /a /v.

  3. Save the file to the hard drive using the .bat extension.

  4. Locate the saved .bat file and execute it to test its behavior. If the batch file has any trouble, reopen the file and correct the problems before saving it again.

  5. Once the file is working fine, use the Scheduled Task Wizard to create a new scheduled task that runs the batch file.




PC User's Bible
PC Users Bible
ISBN: 0470088974
EAN: 2147483647
Year: 2007
Pages: 372

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net