MSIcode Scripting Technology for Windows Installer

RSS Author RSS     Views:N/A
Bookmark and Share         
Introduction

In addition to the visual setup editors found in most setup authoring tools, InstallAware provides a human readable, branching setup script called MSIcode. Available only with InstallAware, MSIcode offers a dragdrop scripting environment that introduces branching, script-driven execution logic into Windows Installer. Yet, InstallAware does this without requiring any external scripting engine that needs to be installed as a scripting runtime before-hand. InstallAware automatically compiles the MSIcode setup script into a pure, independent, 100% logo compliant MSI file at build time. This shifts the burden of properly populating MSI database tables and creating custom actions (the latter an especially error prone process) from the developer to the setup IDE, providing developers with unprecedented levels of flexibility in coding their setup logic. Such flexibility was unavailable since the initial launch of Windows Installer in 1999.

MSIcode

One of the key strengths of InstallAware 7 is the unique architecture it employs for creating Windows Installer packages.

While all other setup tools for Windows Installer provide high level visual editors for creating Windows Installer packages, none of them offer a native scripting capability for Windows Installer. Any scripting that is offered either requires an external scripting engine, which needs to be pre-installed and thus adds an extra layer of complexity to setups; or executes directly through another scripting technology which does not require to be pre-installed before use.

Even though this approach is suitable, it bifurcates installation projects into two disparate sets - one that goes through Windows Installer, and another that goes through the third party scripting engine (which may or may not need to be pre-installed). Separate editors and environments must be mastered for these two independent aspects of setup projects, and this increases the burden on the developer. It also complicates the development process as the two separate parts can interact with each other in unexpected ways and have unexpected dependencies. InstallAware has addressed this problem since its very first release in a conceptually clean, technically sound manner.

Types of MSIcode Commands

InstallAware 7 presents a single, unified MSIcode script which effectively deals with the bifurcation problem. The MSIcode script is the heart of the installation and has complete control over what happens - and when.


A Single Script for Installs, Maintenance, and Uninstalls

Another time saving feature offered by MSIcode technology is having a unified script for the entire install/maintain/uninstall cycle. If parts of an application are to be removed during a maintenance operation, and other parts added, absolutely no additional scripting code is required to install the new parts, or remove the old parts. And of course, no scripting code is required to remove all installed parts during an uninstallation.

A script with manual coding for the install/maintain/uninstall cycles could look like the following:

If Installing or Maintaining
If Feature A is Selected
Install File Set A
If Feature B is Selected
Install File Set B
End

If Maintaining
If Feature A is Not Selected
Remove File Set A
If Feature B is Not Selected
Remove File Set B
End

If Uninstalling
Remove File Set A
Remove File Set B
End

With InstallAware, you have a much simpler script that does everything in one place. If parts of your application are no longer needed, InstallAware automatically removes them (during either a maintenance operation, or an uninstallation) - no manual coding is necessary. If new parts of your application must be installed, InstallAware automatically adds them. All powered by the same block of code - including the first time install:

If Uninstalling
Modify System: Apply Uninstall
If Installing or Maintaining
If Feature A is Selected
Install File Set A
If Feature B is Selected
Install File Set B
Modify System: Apply Install
End

When you compare the two code listings above, you immediately see that MSIcode, through its unified scripting model, saves you many lines of manual coding for the maintenance and uninstallation cycles of your application, while still operating on a highly customizable scripting model.

Limitations of MSIcode

Because each InstallAware setup is still based on Windows Installer technology, there are some unavoidable restrictions. Fortunately these are very few, and will not impact most setups. Moreover, these restrictions would apply to any setup based on Windows Installer technology - regardless of whether InstallAware or another Windows Installer tool was used.

The first limitation is that loops are not supported. While the InstallAware script contains constructs that allow you to code loops, if you execute a Windows Installer statement multiple times within a loop, only the last iteration of that command will actually run on the target system. Because InstallAware cannot determine at compile time the number of times a command located inside a loop may execute, it can populate only a single set of Windows Installer table structures for that command. At runtime, even though the command may execute multiple times, only its last iteration will have any effect. This is because only the last execution's setting of internal Windows Installer conditions will survive - the previous internal conditions will all have overridden one another.

The second limitation is that no changes are actually made to the target system when a Windows Installer command executes. You may think of this as InstallAware caching and queuing the command for deferred execution. The deferred commands are all executed at once when one of the Modify System commands are called (Apply Install, Apply Advertised, Apply Patch, Apply Uninstall). Apply Install installs the application, Apply Advertised installs the application in advertised mode, Apply Patch patches a previously installed application, and Apply Uninstall removes an application. Because Windows Installer does not permit conditional program flow, the only alternative to this approach would be immediately applying changes to the system any time a Windows Installer command was called. While the InstallAware development team investigated this option early during development, it caused extremely severe drawbacks in execution time and was abandoned.

The impact of either limitation on installation development is very small.

For the first limitation, very rarely would commands that change the target system reside inside a loop. In fact, in the entire range of setup scripts developed by InstallAware Software Corporation, including internal development and external consulting projects, none of the setups had this requirement.

As for the second limitation, conditions that require setup commands to be applied immediately are also rare - they only occur under circumstances in which the setup flow branches based on the outcome of a preliminary setup command. If you do have a need for such branching, you will be relieved to learn that InstallAware allows you to call the Apply Install command more than once in your script, effectively sidestepping this limitation. The only drawback is that each time Apply Install is called, the Windows Installer engine is invoked - which performs a complete installation routine every time. Therefore calling Apply Install multiple times may degrade your installation speed, especially if the calls come after large blocks of file copy operations.

"Non-Windows Installer" MSIcode Commands

As extensive a setup engine Windows Installer is, it does not provide the total set of installation commands - and conveniences - that one expects to find in a complete, self-contained installation authoring environment. InstallAware 7 provides an extended, user customizable set of MSIcode commands which save you both time and effort in developing application installations.

Get System Information

Built-in MSIcode commands, which fall under the generic Statement category, offer ways to obtain extensive system information, including hardware properties (physical memory, display resolution), software properties (the running operating system, third party applications), user properties (privilege level, logged on user/domain/computer name), and more.

Advanced Install Actions

Statements are also available which perform advanced installation actions. For instance, you may create and update IIS websites and virtual folders. You can share folders or remove existing shares. You may set permissions on file system, registry, or other types of system objects. You may connect to a wide variety of database platforms and execute SQL scripts, including MS SQL, My SQL, and Oracle database servers (no client software is required on the target machine to connect to remote servers).

Run Programs, Call Dynamic Link Libraries

A very convenient way to extend the behavior of your MSIcode scripts is to call outside code - especially if you've already encapsulated such code into stand alone executable files or dynamic link libraries. InstallAware lets you run any external program, or call any arbitrary dynamic link library function with a variable list of parameters, all directly from your MSIcode script. The InstallAware 7 IDE also makes it even easier to run programs in your setup finish dialog, or before/after the main installation/uninstallation.

Plug-In Extensibility


This is just one example for a case where InstallAware automation takes a major burden off of your shoulders. There are countless other uses for this technology. Some InstallAware licenses even permit you to redistribute the automation libraries, so you can emit and build installers directly on end-user systems! For instance, consider a screen saver creator application - each screen saver it generates would also need an installer. Developing a home made installer for the screen savers produced would be a major undertaking. With a redistributable automation interface, you can simply call the InstallAware library functions and let InstallAware do what its best at - building setups - while you get to focus on your core expertise.

The automation interface is cleanly encapsulated inside Win32 DLLs which can be called from any Windows programming language. The automation interface also provides an ASP object which can be called from an Active Server Pages website.

The InstallAware Customer Site, which vends licenses to developers who have purchased InstallAware, uses the automation interface to create watermarked installers that contain the name of the individual or organization that purchased the license.

Compiler Variables

There may also be cases in which you need to customize your installers - but not as thoroughly as needing to use the automation interface. For instance, you may have several editions for a product, each with progressively more features and higher prices. When building the installers for these various editions, instead of coding multiple scripts for each, you would rather code and maintain a single script. In this case, using the automation interface would be overkill - another way to quickly customize the script becomes necessary.

Compiler variables are resolved at build time, and let you achieve the following:
• Include or exclude various parts of MSIcode based on compiler variable values
• Substitute compiler variables used in MSIcode commands with their literal values

Continuing our example with the various editions, you could use Compiler Variable If statements to conditionally include/exclude parts of your MSIcode, and hence, application files, based on the product edition. You could also use compiler variables directly in MSIcode commands for build time substitution of their values into the script (such as, the edition name).

Report this article

Bookmark and Share



Ask a Question about this Article