HOW TO: Use Launch Conditions in a Microsoft Windows Installer Package (827021)



The information in this article applies to:

  • Microsoft Windows Installer
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Platform Software Development Kit (SDK) 1.0

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 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Primary Interop Assemblies 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:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Windows Application, and then click OK. By default, Form1 is created.
  5. Add a Button control to Form1.
  6. Paste the following code in the Button1_Click event handler:
    MessageBox.Show("This is a test Windows Installation package")
  7. On the Build menu, click Build Solution.
  8. On the File menu, point to Add Project, and then click New Project.
  9. Under Project Types, click Setup and Deployment Projects.
  10. Under Templates, click Setup Project.
  11. In the Name text box, type MyApp, and then click OK.
  12. In Solution Explorer, right-click MyApp, point to Add, and then click Project Output.
  13. In the Add Project Output Group dialog box, click OK.
  14. In Solution Explorer, right-click MyApp, and then click Build.
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:
  1. Start Orca.

    Note To download and to install Platform SDK (including Orca), visit the following Microsoft Web site: 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.
  2. On the File menu, click Open.
  3. In the Open dialog box, locate the MyApp.msi file, and then click Open.

    Note This file is located in the MyApp\Debug folder.
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 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Primary Interop Assemblies 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 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Primary Interop Assemblies 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:
  1. Locate the MyApp.msi file on your computer. This file is located at MyApp\Debug folder.
  2. Right-click MyApp.msi, and then click Install. If your computer does not have the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Primary Interop Assemblies registry key, you receive the following message and the installation is not completed:The Primary Interop Assemblies registry key does not exist.
back to the top

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

307353 HOW TO: Create a Setup Package by Using Visual Studio. NET

307374 HOW TO: Use Launch Conditions in Visual Studio .NET

For more information about launch conditions, visit the following Microsoft Developer Network (MSDN) Web site:back to the top


Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbPackage kbHOWTOmaster kbhowto kbSDK kbtable kbsetup kbDeployment KB827021 kbAudDeveloper