Automate complex setup tasks with ScriptIt
How often have you needed to automate a Windows NT task that doesn't have a command-line interface or a scripting solution? Sound driver and modem installations are perfect examples of tasks that run only through a GUI on NT 4.0 systems. In past acts of desperation, I've copied the old macro recorder from my Windows 3.11 system to an NT computer to automate a setup routine.
Fortunately, one of my coworkers found a free tool called ScriptIt on Microsoft's Web site that automates tasks in a GUI and requires minimal configuration. In this article, I'll describe ScriptIt's capabilities and provide examples of how you can use this utility to automate tasks you probably didn't think you could automate.
ScriptIt Does the Hard Work
When you download ScriptIt, you get three files: the ScriptIt executable, a .dll, and documentation that explains how to use the software. ScriptIt takes as input a simple text-based .ini file that contains the commands you want the tool to run and the names of the windows you want the tool to run those commands in. (Because the ScriptIt file is a simple text file, its filename doesn't have to end in .ini.) The utility processes these commands in order until it reaches the end of the file. ScriptIt isn't a programming language, and it doesn't contain any of the usual programming constructs (e.g., looping, conditional statements). However, the commands and functions that ScriptIt supports allow you some creativity. For example, you can include system environment variables when you tell ScriptIt what keystrokes you want to send to a given dialog box. You can also call built-in command shell (DOS) commands and redirect the output of these commands to windows. This functionality lets you make your scripts somewhat dynamic, which is helpful if you need to automate a task that varies slightly depending on the target system's characteristics.
ScriptIt's best feature is its ability to watch and wait for specific windows to appear on your desktop. If you tell ScriptIt to perform a function in a certain window, the tool waits until the window opens to perform that function. When the window opens, ScriptIt sends the keystrokes you specified to the intended dialog box. Keystroke recorders' automation scripts usually break down when a window event occurs out of sequence or when a window that the program doesn't expect pops up. These automation scripts aren't flexible because most keystroke recorders automatically replay your exact keyboard and mouse movements. ScriptIt is intelligent enough to wait for a specific window before performing a particular action.
To install a sound driver, I click Multimedia in Control Panel, select the Devices tab, and click Add. Then I choose a driver from the resulting list or select another destination if my driver isn't in the standard NT source files. After I select the driver, I might need to confirm hardware settings (e.g., IRQ, direct memory access--DMA). These steps might vary depending on the hardware platform I install to because different hardware devices (or even newer versions of the same hardware device) use different sound chips. With ScriptIt, you can use the same .ini file to automatically install drivers for different hardware configurations. You can vary the window names the tool watches for and the keystrokes ScriptIt sends to adapt to the configuration it's installing on.
How the Scripts Work
The ScriptIt documentation describes the options you have within the ScriptIt .ini file. Each .ini file can have two sections: Script and Adlib. You must place these section names in brackets (e.g., [Script]), as you do in standard .ini files. The Script section contains your main ScriptIt commands. The optional Adlib section contains commands for your script to perform when unexpected events occur. For example, after you set up a particular service or appli-cation for the first time, different windows or dialog boxes might appear during subsequent setups on the same system. You add commands to the Adlib section to account for these differences within the same setup script. The Adlib section is similar to a primitive exception handler.
After you create your input file, running a script is simple. From a command line or batch file, you call ScriptIt with the name of the input file:
scriptit c:\temp\myfile.ini
Using the Commands
Within the Script section of the input file, you can use five commands: run, runwait, mkfile, REM, and title. The run command initiates an executable program, batch file, or DOS command. The runwait command instructs ScriptIt to wait until a process completes before continuing to the next command. Some setup routines return control to the calling process before the routines complete. If you're trying to automate sequential tasks, ScriptIt's return to the .ini file before a process finishes can cause timing problems; runwait solves those problems. However, use the runwait command with caution. If you tell runwait to wait for a process to complete and the command you're waiting on fails, your script won't complete.
The mkfile command creates files or scripts as the ScriptIt script runs. Mkfile tells ScriptIt to create a file, then passes a line of text to that file. The line of text the software passes to the file is the text you type on the mkfile line. For example, if a ScriptIt script contains the line
mkfile script.log=This script is running now
ScriptIt creates a file called script.log that contains the text This script is running now. If a script.log file already exists, mkfile appends the line of text to the end of the file. You can use mkfile to create a script in your favorite scripting language and call that script from within ScriptIt. For example, if you have the Windows Scripting Host (WSH), you can use mkfile to create a JScript file, then use the run command later in the ScriptIt script to call that file.
You can use REM statements to place comments within your script. ScriptIt doesn't process REM statements.