To create custom installation packages, administrators can use Microsoft Systems Management Server (SMS) Installer, which ships with SMS 2.0. SMS Installer's Installation Expert mode provides a GUI to control most aspects of the installation package, including installing files, creating shortcuts, and modifying the Registry. Installation Expert does an acceptable job of creating basic installation packages, but to get the most out of SMS Installer, you'll need to venture into the Script Editor mode. Using Script Editor, you'll get much tighter control over the installation package, and you'll get additional functionality that the Installation Expert mode alone doesn't provide. For example, if you want to use any form of conditional logic (e.g., If...Then statements) in your packages, you'll need to use Script Editor to edit the underlying script. However, if the idea of learning yet another proprietary scripting language is unappealing, don't worry—because Script Editor uses a GUI and simple programming concepts.
Getting Familiar with Script Editor
The Script Editor GUI, which you access through the View menu, has two panes. The left pane lists all the available actions, which are distinct commands or tasks that the installation package will run. Common actions include setting variables, installing files, creating shortcuts, and modifying the Registry. The right pane displays the active script, as Screen 1 shows. At the top of the window, a menu bar and a toolbar contain the ubiquitous File and Edit commands and a handful of other common scripting commands.
The most common method to create an installation package is to use the Installation Expert's repackage wizard to automatically generate the basic script. When you switch into the Script Editor mode after creating the package, the script in the right pane will contain the script-equivalent of all the actions that the repackage wizard captured—each line of the script represents an action.
Roughly the first 40 or 50 lines of the script contain basic housekeeping actions, such as declaring variables and structuring the wizard dialog boxes. Be careful not to change or delete these actions because they're vital to the script's operation. For example, if your installation package displays a progress bar during installation, the script won't compile without the Check Disk Space action.
If you've already used the Installation Expert to repackage an application, you'll find a series of Install File actions that correspond to each file that the installation package will copy onto the client computer. Near the end of the script, you'll find a few Create Shortcut actions and an Edit Registry action, although the presence of these actions depends on which application you're installing.
You can add a new action to the script in several ways, but the simplest method is to drag an action from the left pane to the desired location in the script in the right pane. The script editor appears to use a text-based scripting language, but it uses dialog boxes for the script actions. When you add or modify an action, a dialog box lets you edit the action using Windows controls, such as check boxes and drop-down menus.
One of SMS Installer's more useful features is its ability to automatically use variables for common directory locations. For example, if you create an installation package on a Windows 9x machine that places files in the C:\windows\system directory, SMS Installer will replace all references to C:\windows\system with the SYS variable. If you install that package on a PC running Windows NT, the package will intelligently copy those files into the \winnt\system32 directory. Likewise, the installation package can place shortcuts in the active user's profile rather than simply copy the shortcuts to a static location.
If you're familiar with editing the Registry, you can use the same technique to make your installation packages more reliable. Suppose you want to distribute a plug-in DLL to your Microsoft Internet Explorer (IE) users. You can use the Installation Expert to create an installation package that copies the DLL to program files\internet explorer\plugins, and the installation package will probably work well for most users. However, if you have IE installed in a location such as D:\ie4 or C:\program files\plus!\microsoft internet and try to run the package, the installation package won't work. To avoid installing the DLL to the wrong location, you can use the Get Registry Key Value action to read the IE location from the Registry into a new variable, as Screen 2 shows. You can use the variable name (e.g., IEPATH) when installing files, as Screen 3 shows. The Registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IE Setup\Setup contains the path value that shows which directory IE resides in, as Screen 2 shows. If you read the value into a new variable called IEPATH, then you can specify that the package copies the plug-in file to the %IEPATH%\plugins directory. This specification ensures that the installation package will work for all users regardless of which directory IE resides in.
You might need to spend some time searching the Registry to pinpoint the location of the information you need (e.g., the path to IE), and you'll want to test several configurations to ensure that the Registry location is consistent. For instance, PCs that have only IE 3.0 installed have no such IE path Registry key, so the previous example would work only for users of IE 4.0 or later.
If you've programmed, you know how indispensable the If...Then construct is. Not surprisingly, conditional statements are also useful in SMS Installer. You can use conditional statements to manage tasks such as modifying package behavior, depending on the OS. You can also use conditional statements to exit the installation if a particular application isn't present or to perform various actions, depending on which user is logged on.
The If/While action, which Screen 4 shows, uses an operator (e.g., Equals, Contains) to compare a variable to a value that you specify. The script can use the result of the comparison to start an If block or a While loop. Next, you insert the actions you want to perform after the If/While action and close the conditional statement with an End Block action.
Other actions also perform conditional operations. For example, the Check Configuration action can branch the script depending on the system's hardware or software. The configuration check appears in the script as an If statement, such as If the system has Windows 95 running, abort installation. If you plan to use SMS to distribute your packages, SMS can handle most of the requirements checks, such as preventing packages from running on anything except NT or Win9x. You can also add an Else statement to provide an alternative series of actions when the If condition is invalid, as the following example shows:
Else End Block
Other Useful Actions and Variables
You might find that you can use variables, modify the system Registry, and use conditional statements to accomplish 99 percent of your installation requirements. To meet the final 1 percent of your installation needs, a few additional actions and variables are worth mentioning.
Delete File(s). Although Installation Expert will let you install files to a user's system, it provides no way to delete existing files. To delete files, you need to use the Delete File(s) action in Script Editor.
Suppose you're creating a system-cleanup application. As part of the application, you want to prevent Microsoft Find Fast from launching at startup. You can simply add a Delete File(s) action to the script that tells the application in which directory to find the shortcut file that you want to delete, as Screen 5 shows. You must use a variable to describe the file location, so you need to set up this variable ahead of time or use one that SMS Installer provides, such as STARTUPDIR.
You can use wildcards in your delete statements, except within the system directories such as \windows and \winnt\system32. Additionally, the Delete File(s) dialog box provides check-box options that let you delete files within subdirectories and remove the directories that contain the files.
Depending on which version of SMS Installer you use, the options to include subdirectories and remove directories might not work correctly. For more information about how to correct problems that occur when using the Delete File(s) function to remove directories, see the Microsoft article "SMS: Remove Directory Containing Files Option in 'Delete Files' Script Item Not Functioning Properly" at http://support.microsoft.com/support/kb/articles/q235/7/48.asp. For more information about SMS Installer bug fixes, see the sidebar "SMS Installer Fixes." SMS Installer 2.0.91.00 doesn't exhibit problems using the Delete Files function to remove directories, and this version includes enhancements such as color-coding script actions, debugging features, and new actions. For more information about SMS Installer 2.0.91.00 enhancements, see the sidebar "SMS Installer 2.0.91.00 Enhancements."
Parse String. Sometimes you might need to use only a portion of a variable or split one variable into two variables. For these functions, you can use the Parse String action. Parse String lets you trim or split a variable based on a numerical position or a search pattern that you specify.
Suppose your script needs the version of an installed application to determine what action to take next. You've found the Registry entry that contains the version number (e.g., 2.0.1b, 3.0.5a). If you only want to know the major version number (e.g., 2.x, 3.x), you can parse the string to return only the first character. You can use the Parse String action to select Split value at position from left and specify 1 as the Pattern/Position. This action captures the first character of the version number in a variable that you specify. Then you can use an If statement to branch the script depending on the value of your variable.
Include Script. To organize your scripts and make them modular, you'll find the Include Script action useful. As the name implies, Include Script lets the active script include the entire contents of another script file. For example, SMS Installer uses the Include Script action to provide uninstall support. SMS Installer includes the uninstal.ipf file, which copies the appropriate uninstaller executable and creates the necessary Registry entries. Then, you can use the Control Panel Add/Remove Programs applet to remove the application. SMS clients can also use this uninstall feature to automatically remove an application that SMS is no longer publishing.
RESTART. Ordinarily, when your script performs actions such as system file replacement or autoexec.bat modification, your installation package prompts the user to reboot the system when the installation completes. To override this behavior, you can use the RESTART variable, which determines whether the installation package restarts the system. If you set the RESTART variable's value to an empty string, the package will skip the reboot. To make the package skip the reboot, add a Set Variable action to the end of your script and set RESTART to an empty string. Be careful using this technique because many applications won't work properly until after a system reboot. However, if you plan to use SMS to deploy a series of installation packages together, delaying the reboot until after you install the last package is more efficient.
You can also use the RESTART variable to force a reboot after installing a package that doesn't ordinarily require a reboot. You set the RESTART variable to S to signal and force the reboot. Or, if you use SMS to distribute the installation package, you can configure the program settings within SMS to automatically initiate the restart without using the RESTART variable.
Regardless of whether you use Script Editor or Installation Expert, you need to perform a few cleanup tasks on all your installation packages before you deploy them. Look through the list of files that the installation package will install and remove temporary files, files in the Recycle Bin, and files relating to background tasks, such as SMS or antivirus log files. During the repackage process, you can specify exclusions to prevent most of these files from appearing, but a double check before finalizing your package is always a good idea.
You might also need to remove files and Registry entries that reference a specific user. If you ran the repackage wizard while logged in as jsmith, the wizard might have captured Registry changes to the HKEY_USERS\jsmith key or installed files to the jsmith profile.
If you've elected to include uninstall support with your installation package, SMS Installer will add an Uninstall key to the Registry that you can initiate through the Control Panel Add/Remove Programs applet. If you repackage an application that already has uninstall support, consider excluding the application's Start menu uninstall shortcut to prevent having two different methods of removing the application.
By getting familiar with Script Editor in SMS Installer, you'll learn to use a much more powerful and flexible set of tools than the Installation Expert mode offers. You can use variables and conditional statements to create reliable packages to distribute applications and reconfigure clients with precise control.