Walkthrough: Creating a Custom Action

The following walkthrough demonstrates the process of creating a DLL custom action to direct a user to a Web page at the end of an installation. You can use custom actions to run code at the end of a Windows Installer installation to perform actions that cannot be handled during installation.

Note

The dialog boxes and menu commands you see might differ from those described in Help, depending on your active settings or edition. To change your settings, click Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Note

The following instructions use a Visual Basic project as an example to demonstrate how to create a deployment. The general principles apply to all Visual Studio language projects that support deploying Windows-based applications.

To create the custom action

  1. On the File menu, click New Project.

  2. In the New Project dialog box, select Visual Basic Projects in the Project Types pane, and then click Class Library in the Templates pane. In the Name box, type OpenWeb.

    The project is added to Solution Explorer.

  3. On the Project menu, click Add Class, and then in the Add New Item dialog box, select Installer Class. Accept the default name of Installer1.vb. Click Add.

  4. Switch to code view by clicking click here to switch to code view on the design surface (or by right-clicking the design surface and clicking View Code).

  5. In the Code Editor, add the following code (which opens a Web browser) to Installer1.vb, under the constructor:

    <Security.Permissions.SecurityPermission(Security.Permissions.SecurityAction.Demand)> _
    Public Overrides Sub Commit(ByVal savedState As _
      System.Collections.IDictionary)
    
      MyBase.Commit(savedState)
      System.Diagnostics.Process.Start("https://www.microsoft.com")
    End Sub
    

    Note

    If you type Public Overrides and then type space, IntelliSense will provide a list of methods and properties; you can select Commit from the list and get the complete declaration.

  6. In Solution Explorer, right-click Class1.vb and then click Delete (because it is unnecessary).

To add a deployment project

  1. On the File menu, point to Add, and then click New Project.

  2. In the Add New Project dialog box's Project Type pane, open the Other Project Types node, and then select Setup and Deployment Projects. In the Templates pane, click Setup Project. In the Name box, type Custom Action Installer.

    The project is added to Solution Explorer and the File System Editor is displayed.

  3. In the File System Editor, select Application Folder in the left pane. On the Action menu, point to Add, and then click Project Output.

  4. In the Add Project Output Group dialog box, OpenWeb will be displayed in the Project list. Select Primary Output.

    Primary Output from OpenWeb (Active) appears in the Application Folder.

To add the custom action

  1. Select the Custom Action Installer project in Solution Explorer. On the View menu, point to Editor, and then click Custom Actions.

    The Custom Actions Editor is displayed.

  2. In the Custom Actions Editor, select the Commit node. On the Action menu, click Add Custom Action.

  3. In the Select Item in Project dialog box, double-click the Application Folder. Select Primary output from OpenWeb.

    Primary output from OpenWeb appears under the Commit node in the Custom Actions Editor.

  4. In the Properties window, make sure that the InstallerClass property is set to True (this is the default).

  5. In the Custom Actions Editor, select the Install node and add Primary output from OpenWeb to this node as you did for the Commit node.

  6. On the Build menu, click Build Custom Action Installer.

To install on your development computer

  • Select the Custom Action Installer project in Solution Explorer. On the Project menu, click Install.

    This will run the installer and install Custom Action Installer on your development computer. At the end of installation, Internet Explorer should start and should open the Microsoft.com Web site.

    Note

    You must have install permissions on the computer in order to run the installer.

To deploy to another computer

  1. In Windows Explorer, navigate to your project directory and find the built installer. The default path will be \Documents and Settings\yourloginname\My Documents\Visual Studio\Projects\Custom Action Installer\Custom Action Installer\project configuration\Custom Action Installer.msi. The default project configuration is Debug.

  2. Copy Custom Action Installer.msi, Setup.exe, and all other files and subdirectories in the directory to another computer.

    Note

    To install on a computer that is not on a network, copy the files to traditional media such as CD-ROM.

  3. On the target computer, double-click Setup.exe to run the installer.

    At the end of installation, Internet Explorer should start and should open the Microsoft.com Web site.

    Note

    You must have install permissions on the computer in order to run the installer.

    Note

    If the .NET Framework is not already installed on the target computer, this deployment will install it, and this installation might take several minutes.

To uninstall the application

  1. In Control Panel, double-click Add or Remove Programs.

  2. In the Add or Remove Programs dialog box, select Custom Action Installer and click Remove.

    Tip

    To uninstall from your development computer, with the Custom Action Installer project open and selected in Solution Explorer, from the Project menu, click Uninstall.

See Also

Concepts

Custom Actions

Other Resources

Custom Actions Management in Deployment