Tuesday, March 31, 2009

Frequently Asked Questions About Windows Installer (MSI) Packaging

These are the most Frequently asked queries about Windows Installer.
Q. What is Windows Installer?
A. Windows Installer is a system service for installing and managing applications. It provides a standard method for developing, customizing, installing, and updating applications.

Q. What basic functionality is provided by Windows Installer?
A. Windows Installer provides the following basic functions:
Transactional operations: All installation operations are transactional. For each operation that Windows Installer performs, it generates an equivalent undo operation that would undo the change made to the system. If a failure occurs during the middle of an installation, Windows Installer can roll back the machine to its original state.
Self-healing: Windows Installer supports "self-healing" abilities for applications. Applications can detect common installation problems at launch, like missing files or registry keys, and automatically repair themselves.
Installation on demand: Windows Installer supports on-demand installations of application features. For example, the spelling checker in Microsoft Office Word may not be installed by default, but a user can trigger an on-demand installation of this feature.
Installation in locked-down environments: In fully locked-down environments, users don't generally have permission or the ability to install applications. In most cases, they don't have write-access to the Program Files folder of their computers or to the HKEY_LOCAL_MACHINE registry location. If an administrator approves an installation package by means of Group Policy, for instance, Windows Installer can perform an installation on the user's behalf.
State management: Windows Installer provides a set of standard Win32® application programming interfaces (APIs) and automation interfaces for applications and administrators to use for querying the installation state on the machine. The APIs allow querying of the current state, verification of the existing state, repair of a corrupted state, and transition from one state to another.

Q. What versions of Windows include Windows Installer?
A. Microsoft Windows 2000, Windows Millennium Edition (Windows Me), and Windows XP include Windows Installer. Windows 2000 includes version 1.1 of Windows Installer, Windows Me includes version 1.2, and Windows XP includes version 2.0. Windows 2000 SP3 also contains version 2.0 of Windows Installer.

Q. Why are multiple MSIExec.exe processes running on my machine during an installation?
A. A number of MSIExec processes can be running during an installation. The reason for this is that Windows Installer uses a client-server model for performing installations. Additionally for security reasons, Windows Installer hosts DLL and script custom actions in a "sandbox" process. Depending on how the install was initiated, one of the MSIExec processes can be the client process. Another MSIExec process is Windows Installer service. Any remaining MSIExec processes are usually sandbox processes for hosting custom actions. The determination as to which MSIExec process will serve as the sandbox process for a script or DLL custom action depends in part on whether the custom action will run elevated or impersonated and whether the custom action is 32-bit or 64-bit.

Q. What is an MST, and why it is used?
A. Whenever there is a vendor supplied MSI, then it is not recommended to do capture the MSI, hence all the changes need to be done in the MSI are done is a Microsoft Transform. Then this MST file is applied on the MSI with the following command line.
MSIEXEC /I {path}\file.msi TRANSFORMS={path}\file.mst /q

Where {path} is the location of the folder where MSI and MST are kept.

Q. What are the differences between small, minor, and major updates?
A. A small update is a product update that changes a few files or possibly adds some new content. A minor update is a product update that makes enough changes to warrant changing the product version for the product, whereas a major update is a product update with a large number of changes that warrants a change in the product code.
It's sometimes easier to think of a small update as a "hotfix" or Quick Fix Engineering (QFE) update, a minor update as a service pack, and a major update as a product upgrade.
Small and minor updates can be considered almost equal in that the only real difference is that a minor update has a change to the ProductVersion whereas a small update does not. The rules that they follow and application of the patch are the same. Application of small and minor update patches requires explicit reinstallations. Major updates are not subject to that limitation and a reinstallation is not required for patch application. Additionally small and minor update patches are limited in the changes that can be made to the feature-component structure for the package. Significant changes can be made to the feature-component structure in the scope of a major update.

Q. What is the Logical structure of package?
A. A package describes the installation of a full product (Windows Installer does not handle dependencies between products) and is universally identified by a GUID. A product is made up of components, grouped into features.

1. Components
A component is the minimal part of a product-each component is treated by Windows Installer as a unit: the install developer cannot, for example, use a condition to specify to install just part of a component. Components can contain files, groups of files, directories, COM components, registry keys, shortcuts, and other data. The end user does not directly interact with components.
Components are identified globally by GUIDs, thus the same component can be shared among several features of the same package or multiple packages, ideally through the use of merge modules (although, for this to work correctly, different components should not share any sub-components).

2. Key paths
A key path is a specific file, registry key, or ODBC data source that the package author specifies as critical for a given component. Because a file is the most common type of key path, the term key file is commonly used. A component can contain at most one key path; if a component has no explicit key path, the component's destination directory is taken to be the key path. When an MSI-based application is launched, Windows Installer checks the existence of these critical files or registry keys (that is, the key paths). If there is a mismatch between the current system state and the value specified in the MSI package (e.g., a key file is missing), then the related feature is re-installed. This process is also known as self-healing or self-repair. No two components should use the same key path.

3. Features
A feature is a hierarchical group of components-a feature can contain any number of components and other features (a feature contained in another feature is called a "subfeature"). Most installation programs display a "custom setup" dialog box at run time, from which the end user can select which features to install or remove.
The package author defines the product features. A word-processing program, for example, might provide features for the main program executable, the program's help files, and optional spelling checker and stationery modules.

Q. What is Advertisement?
A. Windows Installer can advertise a product rather than actually installing it. The product will appear installed to the user, but it will not actually be installed until it is run for the first time (by means of a Start menu shortcut, by opening a document that the product is configured to handle, or by invoking an advertised COM class).

Q. What is Installation on demand?
A. Similar to advertisement, it consists in the installation of features as soon as the user tries to use them.

Q. How to do Diagnostic Logging?
A. Windows Installer supports detailed logging as a powerful diagnostic tool. Logging can be enabled in the following four ways:
Command-line: If installing an MSI package from the command-line, the /L switch can be used to enable logging. For example, the following command installs Package.msi and outputs verbose logging to c:\Package.log:
msiexec /i Package.msi /l*v c:\package.log

Windows Registry: The following registry value can be used to enable verbose logging:

Key: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer

Value Name: Logging

Type: REG_SZ

Data: voicewarmup

The resulting log is named MSI###.log (where "###" is a unique random identifier) and is placed in the system's Temp directory.

Group Policy: The following Group Policy setting can be used to manage logging on multiple systems:

Computer Configuration -> Administrative Templates -> Windows Components -> Windows Installer -> Logging.

Windows Installer API: If installing an MSI package programmatically, the MsiEnableLog function call can be used to create a log file and determine the logging level for the life of the calling process.

Although verbose logs are very useful for diagnosing Windows Installer problems, they can be very long and difficult to read without practice. A quick way to find the location of a problem in the log is to open it in a text editor (such as Notepad) and search for the phrase "Return Value 3". This entry commonly appears in logs close to the point where a critical error has occurred. The Windows Installer SDK provides a tool called WiLogUtl, which parses and annotates Windows Installer log files.

Q. Why does the package go for Self Healing first time the user launches the Application?
A. If the package is containing some HKCU entries then the package will always go for self healing for the first time. This happens because the HKCU keys are only installed for the current user present while installing the package and not all the users as it is the property of the HKCU. So, if other user logs in then there is a mismatch between the current system state and the value specified in the MSI package (e.g., a key file is missing), then the related feature is re-installed. This is called the Self Healing.

Basics of MSI

MSI files are basically relational database files that contain all the information that the Windows Installer requires to install or uninstall an application and to run the setup user interface. Installation packages are organized like the diagram above. Each package has one or more independent features. Each feature can have one or more components. The installer always installs or removes a component from a user's computer as a coherent piece. A component can be a single file, or a group of files, a registry setting, COM objects, resources, etc.

1. Installation Mechanism
There are two phases to a successful installation process: acquisition and execution. If the installation is unsuccessful, a rollback phase may occur.

2. Acquisition
At the beginning of the acquisition phase, an application or a user instructs the installer to install a feature or an application. The installer then progresses through the actions specified in the sequence tables of the installation database. These actions query the installation database and generate a script that gives a step-by-step procedure for performing the installation.

3. Execution
During the execution phase, the installer passes the information to a process with elevated privileges and runs the script.

4. Rollback
If an installation is unsuccessful, the installer restores the original state of the computer. When the installer processes the installation script it simultaneously generates a rollback script. In addition to the rollback script, the installer saves a copy of every file it deletes during the installation. These files are kept in a hidden, system directory. Once the installation is complete, the rollback script and the saved files are deleted. For more information, see Rollback Installation.

Advantages of Using MSI based Installations

MSI provides a host of advantages over other installation programs which include but are not limited to:

1. Repair Damaged Installations
At times a clean installation can turn bad owing to a missing file or accidental deletion of some files from the applications folder. This could be due to an error on the user’s part, corrupt files, disk crashes, etc. When run in maintenance mode, MSI based installations provide a “Repair” Mode which allows user to repair their existing applications without bothering to uninstall / re-install the whole application. MSI installer replaces any missing or corrupt files from the files installed on the user’s machine and the system is ready for use. The Windows Installers service identifies the missing or corrupt files from the users system and replaces them from the source media or Network Image.

2. Easy Management of upgrades / patches
MSI supports creation of updates or patches and has an in-built functionality to implement the rules for applying patches on the user’s machine. With the help of its inbuilt version field, the developers need not worry about writing rules for the patch installations.

3. Ability to provide Roll Back in case of a failed installation
This is in all probability the biggest advantage of MSI over other setup types. One of the trickiest things to handle during installations is a state when the half way through the installation needs to be aborted for one or more of the reasons listed below
• The user cancels the installation
• There is an irrecoverable error
• Changes to the state of the system by another application

This often leads to a dirty installation. From the users’ perspective, they would prefer to have their state back as it was prior to commencement of installations. Implementing a complete Roll Back was never a good option with traditional installer software’s owing to time consuming procedures and managing various states of files.

With MSI the Roll Back functionality is in-built and is ready to use out of the box. If the user cancels or aborts the installation in between, the Windows Installer restores the user’s machine to the state it was before the installation started. It restores any deleted files, removes any registry entries done, deletes any folders the installer might have created, etc.

4. If enabled, extensive logging enables easy debugging
With Installations becoming more complex and increased demand for support for installations over the network, it becomes difficult to handle a broken installation package. MSI by default provides logging features which help in providing meaningful information to the users in case of failed installations. The developers need not write additional code to log messages; the logging engine is intrinsic to the MSI Installer and logs each action from the sequence.

5. Ability to customize installations with Transforms
Transforms are additional files that can be associated with the MSI installers to customize the installations. As an example if the installation is to be repeated over several workstations in a Lab, a transform can help in installing the product with a pre-determined set of settings on one machine and replicate the same across all other machines in the Lab.

6. Ability to do a silent installation without any user intervention
In addition to the transforms, MSI can be used to author silent installations with ‘Zero’ user interaction. The installers can read the parameters from a configuration file and complete the installation.

7. Permissions and rights management
In case of traditional installers the installation is run in the context of the user who has logged into the system. This brings up a challenge of handling user permissions and security settings. In case of MSI Installers, the Windows Installer runs as a system service and hence there are fewer issues with respect to security.

8. Network Deployment using Group Policy
When used with Active Directory, an MSI can be associated with a group policy to let end users install the application on their systems even if they don't have rights to modify the file system or registry. The request is passed on to WIS (Windows Installer Service) for the actual install.

What are MSI based Installations?

Windows Installer is an engine you can use to manage the state of an application. The state of an application includes installation, modification, upgrade, or removal.
Windows Installer is not a tool to create and deploy installations, rather it is a service built into the OS. Software-distribution technologies use Windows Installer to install and manage software applications.
The Windows Installer technology is made up of three elements that work together: the Windows Installer client, the Windows Installer service, and the Windows Installer package (an .msi file).

1. Windows Installer Client
The Windows Installer client is any application that calls upon Windows Installer service to perform a task.
The Windows Installer client is responsible for user interactions such as displaying the Setup user interface during an installation. For example, the Windows Installer client uses the Windows Installer service to change the computer state by copying files and writing registry changes.
Some common clients include the following:
a) The Windows-based shell.
b) Add or Remove Programs in Control Panel of Windows XP Professional and Windows 2000 Professional.
c) Windows Installer-enabled applications, such as Office 2000.

2. Windows Installer Service
The Windows Installer service uses information in a Windows Installer package file to manage all phases of installing a program– add, change, upgrade, and remove. The Windows Installer service performs all installation-related tasks as needed by copying files onto the hard disk, making registry modifications, creating shortcuts on the desktop, and displaying dialog boxes to capture user preferences.

3. Windows Installer Packages
Each Windows Installer package (.msi) file contains a database that stores all the instructions for the Windows Installer service and data required to manage the state of a program, such as adding, changing, or removing it from a computer.
Creating and editing all the tables in the database could by itself be a huge task to accomplish.
To simplify creating and customizing .msi files, Software-distribution authoring tool vendors have developed various authoring tools for Windows Installer such as Wise Installer or Installshield Professional.
As is evident from above, since the Installer service is part of the OS, we need not include an engine to carry out the installation, rather we need to supply all the information that is needed by this service to execute the installation. It does not matter what tool has been used to create the MSI package.