Microsoft KB Archive/827021

= HOW TO: Use Launch Conditions in a Microsoft Windows Installer Package =

Article ID: 827021

Article Last Modified on 4/16/2007

-

APPLIES TO


 * Microsoft Windows Installer 2.0
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Platform Software Development Kit-January 2000 Edition

-





IN THIS TASK

 * SUMMARY
 * Requirements
 * Create a Microsoft Windows Installer Package by Using Microsoft Visual Studio .NET
 * Open the Windows Installer File by Using the Orca Editor
 * Add New Tables to the Windows Installer File
 * Use AppSearch in the Windows Installer File
 * Set Launch Conditions in the Windows Installer File
 * Verify That Your Application Works
 * REFERENCES



SUMMARY
This step-by-step article describes how to use launch conditions in a Microsoft Windows Installer package. You can establish launch conditions in your Windows Installer package to quit the installation process and to display a message if specific conditions are not satisfied. You set the conditions based on the value of the property that the AppSearch tool returns.

You can use AppSearch to search for files, registry keys, folders, or Windows Installer components during the installation of your Windows Installer package. If AppSearch locates the item that you specified, AppSearch returns the search results as a property. You can then evaluate this property in a launch condition.

AppSearch uses the information that appears in database tables such as the following when it searches for files, registry keys, and folders:
 * Signature
 * DrLocator
 * RegLocator
 * CompLocator

AppSearch returns its search results as a property value that is located in the AppSearch table. You set launch conditions in the LaunchCondition table based on this property value.

The LaunchConditions action queries the LaunchCondition table and evaluates each conditional statement that is in the table. If any of these conditional statements fail, you receive an error message and the installation is not completed. You can use a table editor tool such as Orca to create or to edit database tables in Windows Installer packages.

This article describes how to search for the  registry key while you are installing the Windows Installer package. This article also describes how to quit the installation process if the registry key does not exist on your computer. The steps in this article describe how to use Orca to modify the Windows Installer (.msi) file and to set the launch condition.

back to the top

Requirements
This article assumes that you are familiar with the following topics:
 * Visual Studio .NET Setup Projects
 * Orca.exe
 * AppSearch

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
 * Microsoft Windows 2000, Microsoft Windows XP, or Microsoft Windows Server 2003
 * Microsoft Visual Studio .NET
 * Microsoft Platform Software Development Kit (SDK)

back to the top

Create a Microsoft Windows Installer Package by Using Microsoft Visual Studio .NET
To create a Windows Installer package by using Microsoft Visual Studio .NET, follow these steps:  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects. Under Templates, click Windows Application, and then click OK. By default, Form1 is created. Add a Button control to Form1.  Paste the following code in the Button1_Click event handler: MessageBox.Show(&quot;This is a test Windows Installation package&quot;)  On the Build menu, click Build Solution.</li> On the File menu, point to Add Project, and then click New Project.</li> Under Project Types, click Setup and Deployment Projects.</li> Under Templates, click Setup Project.</li> In the Name text box, type MyApp, and then click OK.</li> In Solution Explorer, right-click MyApp, point to Add, and then click Project Output.</li> In the Add Project Output Group dialog box, click OK.</li> In Solution Explorer, right-click MyApp, and then click Build.</li></ol>

back to the top

Open the Windows Installer File by Using the Orca Editor
To open the MyApp.msi file and to add a launch condition by using Orca, follow these steps: <ol> Start Orca.

Note To download and to install Platform SDK (including Orca), visit the following Microsoft Web site:

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

After you install Platform SDK, install Orca. To do this, double-click the Orca.msi file that is located in the Bin subfolder of the Platform SDK installation folder.</li> On the File menu, click Open.</li> In the Open dialog box, locate the MyApp.msi file, and then click Open.

Note This file is located in the MyApp\Debug folder.</li></ol>

back to the top

Add New Tables to the Windows Installer File
To add new tables such as the AppSearch table, the RegLocator table, and the LaunchCondition table to the MyApp.msi file, follow these steps:
 * 1) Under Tables in the left pane, verify whether the AppSearch table, the LaunchCondition table, and the RegLocator table exist. If these tables do not exist, perform step 2 and step 3.
 * 2) On the Tables menu, click Add Table.
 * 3) In the Add Tables dialog box, click to select the check boxes for LaunchCondition, AppSearch, and RegLocator, and then click OK.

back to the top

Use AppSearch in the Windows Installer File
AppSearch searches for a registry key based on the information that appears in the RegLocator table. AppSearch also sets the property in the AppSearch table while you are installing the Windows Installer package. To use AppSearch to search for the  registry key on your computer, you must provide the search information in the RegLocator table. To do this, follow these steps:
 * 1) Under Tables in the left pane, click RegLocator, and then click Add Row on the Tables menu.
 * 2) In the Add Row dialog box, click Signature_ in the Name column, and then type REGKEY12345 in the Signature_ - String[72], Required text box.
 * 3) In the Name column, click Root, and then type 2 in the Root - Short, Required text box.
 * 4) In the Name column, click Key, and then type SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Primary Interop Assemblies in the Key - String[255], Required text box.
 * 5) In the Add Row dialog box, click OK.
 * 6) Under Tables in the left pane, click AppSearch, and then click Add Row on the Tables menu.
 * 7) In the Add Row dialog box, click Property in the Name column, and then type REGISTRYVALUE1 in the Property - String[72], Required text box.
 * 8) In the Name column, click Signature_, and then type REGKEY12345 in the Signature_ - String[72], Required text box.
 * 9) In the Add Row dialog box, click OK.

back to the top

Set Launch Conditions in the Windows Installer File
AppSearch searches your computer for the  registry key, and then returns the search results as a property value that is located in the AppSearch table. You can establish the launch condition based on this property. To set the launch condition in your MyApp.msi file, follow these steps:
 * 1) Under Tables in the left pane, click LaunchCondition, and then click Add Row on the Tables menu.
 * 2) In the Add Row dialog box, click Condition in the Name column, and then type REGISTRYVALUE1 in the Condition - String[255], Required text box.
 * 3) In the Name column, click Description, and then type The Primary Interop Assemblies registry key does not exist. in the Description - Localizable String[255], Required text box.
 * 4) In the Add Row dialog box, click OK.
 * 5) On the File menu, click Save, and then close Orca.

back to the top

Verify That Your Application Works
To test your application, follow these steps: <ol> Locate the MyApp.msi file on your computer. This file is located at MyApp\Debug folder.</li> Right-click MyApp.msi, and then click Install. If your computer does not have the  registry key, you receive the following message and the installation is not completed:

The Primary Interop Assemblies registry key does not exist.

</li></ol>

back to the top

<div class="references_section">