As we’ve seen, we can use SMS Installer’s graphical
menus and attribute settings to configure our installation scripts to
suit our specific needs. Under different circumstances, however, these
tools might not give us all the control needed to fully customize our
SMS Installer–generated script file. Likewise, specific situations might
arise in which it’s more efficient or just faster and easier to use a
scripting method to make changes.
It really doesn’t matter how
we go about creating our scripted installation. Remember, we can
generate our initial script using either the Repackage Installation
Wizard or the Watch Application Wizard. These two methods are probably
preferred, as they give us a good basic script that we can customize
using the Script Editor utility. Or we can open the Script Editor
interface to modify an existing script or even begin scripting from
scratch. In this section we’ll explore Script Editor variables and
actions and then look at how to modify installation scripts using Script
Script Editor Variables and Actions
The Script Editor
provided by SMS Installer is a powerful scripting utility. It provides a
vast array of variables and actions (SMS Installer commands) that let
you optimize the script files used by the installation process. Script
variables contain information about the installation being performed. We
can use these variables to hold the information gathered from users
about where to place files. Script variables can also be used to hold
information about which files users want to install. Additionally, a
number of predefined variables contain information about the target
computer system on which you’re installing software.
Before we look at how to
make modifications to a script using Script Editor, let’s review some
common scripting variables and actions. The following tables aren’t
intended as a comprehensive list of all the available variables and
actions, but rather as a short list of those more commonly used.
Refer to the SMS Installer Help for a comprehensive list of scripting variables and actions.
Table 1 lists several predefined variables and the values they are designed to return.
Table 1. Predefined variables
|WIN||The path of the Windows directory—for example, C:\Windows.|
|SYS32||The system directory for Win32 files under Windows NT and higher—for example, C:\Winnt\System32.|
path of the temporary directory on the reference computer. An
application often uses this directory to store DLLs before referencing
|CMDLINE||The command-line options that are passed to the SMS Installer–generated file.|
|PASSWORD||The installation password assigned to a password-protected installation.|
As we write our script,
we can have SMS assign values to existing variables or generate
additional variables to perform functions or hold values. During the
installation, we can create the variables SMS uses to perform various
functions. For example, we can define the values for the four variables
listed in Table 2
as part of the installation script or have SMS prompt for the values
during execution of the installation script. SMS frequently uses these
variables—note especially the DOBACKUP variable, which is used to support the SMS Installer rollback feature.
Table 2. Functional variables
|BACKUPDIR||Defines where the backup files should be located.|
|DOBACKUP||Enables the performance of a backup of all files replaced during an installation.|
|HELPFILE||Identifies the help file to be read and displayed during installation when the user clicks Help.|
|RESTART||Causes the system to be restarted when the script terminates. This variable is generally set automatically.|
As mentioned, you
can also define your own variables in the script. You can use the Set
Variable action or the Prompt For Text action from Script Editor. To
create variables, follow these steps:
In the Installation Expert interface, choose Script Editor from the View menu to display the Script Editor interface, shown in Figure 1.
Figure 1. The Script Editor interface.
you previously closed SMS Installer from the Script Editor interface,
when you next open SMS Installer, Script Editor appears with the
Installation Script pane blank. If you open SMS Installer in the
Installation Expert interface, it loads a default script, which is
displayed in the Installation Script screen when you switch to Script
In the Actions list, double-click the Set Variable action to display the Set Variable dialog box, shown in Figure 2.
Figure 2. The Set Variable dialog box.
the name of the variable you want to create or select a variable to
modify from the Variable drop-down list. Variable names must always
begin with a letter, must be no longer than 14 characters, and must
contain no special characters except underscores.
In the New Value text box, enter the value you want to set the variable to.
an operation that you want performed on the new value from the
Operation drop-down list, if required. Operations include incrementing
or decrementing a numeric value by 1, removing trailing backslashes,
converting a value to all uppercase or lowercase, converting the path
and filename to a short or long filename, or simply performing no
Refer to the SMS Installer Help for examples of how to use the different operations.
check boxes appear at the bottom of the Set Variable dialog box: Append
To Existing Value, Remove Filename, and Read Variable From Values File.
If the variable you entered is a counter and you choose to increment or
decrement its value, select the Append To Existing Value check box. You
can also use this option to append a string value to the current string
value. If you want to remove the filename from a value that has a full
path, select the Remove Filename check box. If you want SMS Installer to
read the variable’s value from a file, select the Read Variable From
Values File select box. Selecting this option will cause the entered
value to be ignored, so select this option only if you’re running your
script from the command line.
Click OK to close the Set Variable dialog box.
To create a variable named APPDIR, for example, in which you set the location of the application’s working directory, enter APPDIR as the variable name and an appropriate path such as C:\TechNet
as the value. When you need to invoke this value in your script,
reference the variable’s value by enclosing the variable name in percent
signs. To create a BACKUP directory for rollback that’s a subdirectory
of the path you entered for APPDIR, your script line would look like
Set Variable BACKUP to %APPDIR%\BACKUP
Set Variable is just one
of the SMS Installer Script Editor actions. In the next section we’ll
look at the more common Script Editor actions.
Common Script Editor Actions
The Script Editor window, shown in Figure 1,
contains a list of SMS Installer Script Editor actions that the
installation script can perform. In this section we’ll look at some of
the more common actions and their functions. Table 3 lists these actions.
Table 3. SMS Installer Script Editor actions
|Add to AUTOEXEC.BAT||Adds or replaces commands and environment variables in the Autoexec.bat file other than the PATH command.|
|Add to CONFIG.SYS||Adds device driver and other statements to the Config.sys file.|
|Call DLL Function||Calls specific Win16 and Win32 DLLs.|
|Check Disk Space||Performs a check of disk space to verify that there’s enough free space to complete the installation.|
|Check If File/Dir Exists||Checks whether a specified file or directory exists on the target computer.|
|Create Directory||Creates a new directory on the target computer.|
|Create Service||Creates a service on a target Windows computer.|
|Delete File(s)||Deletes specified files and directories from the target computer.|
|Edit Registry||Creates or deletes new keys and values in the registry on Windows 95 or later computers.|
|Else Statement||Inserts a logical ELSE statement into the script.|
|Execute Program||Calls an executable to run outside the actual scripted installation.|
|Exit Installation||Terminates and exits the installation.|
|If/While Statement||Inserts IF/WHILE logic into the script.|
the source files used during installation and compresses them into the
installer executable file. These files are uncompressed on the target
computer when the script is run.|
|Prompt For Text||Generates a dialog box to prompt the user for text input such as a filename or directory path.|
|Remark||Adds comments to the script.|
|Rename File/Directory||Finds and renames a file or directory on the target computer.|
|Set Variable||Creates or modifies a script variable.|
As you can see, variables
and actions can be set in your script. You can find more details about
these options in the SMS Installer Help file accessible through the SMS
Installer interface. Don’t expect to become proficient at scripting in a
couple of hours or even a couple of days. We’re talking about a
here, and that takes time to learn and appreciate. But with a little
perseverance you’ll become proficient at using many of these options.