HOW TO: Run an Executable File During a Windows Installer Installation by Using Visual Studio .NET (827018)



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

SUMMARY

This step-by-step article describes how to run an executable (EXE) file during a Windows Installer installation by using Visual Studio .NET. This article describes how to create an EXE file to direct users to the Microsoft home page. It also describes how to add the EXE file as a custom action in a Visual Studio .NET Setup project.

Sometimes, you may want your setup application to perform actions that Windows Installer cannot do. For example:
  • You may want to direct users to your Web site.

    -or-
  • You may want to create a local database on the destination computer during your installation.
Windows Installer provides features that are named custom actions. Custom actions help you to create setup applications that perform actions that Windows Installer cannot do. You can add custom actions to your setup application that run code at the end of your installation. This code can be a DLL, an EXE file, a script, or an assembly.

back to the top

Requirements

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
This article assumes that you are familiar with the following topics:
  • Visual Studio .NET Setup Projects
  • Custom Actions
back to the top

Create an EXE File

To create an EXE file to direct users to the Microsoft home page, follow these steps:
  1. Start Visual Studio .NET.
  2. Create a new Empty Project. To do this, follow these steps:
    1. On the File menu, point to New, and then click Project.
    2. Under Project Types, click Visual Basic Projects.
    3. Under Templates, click Empty Project.
    4. In the Name text box, type MyEXE. Click OK.
  3. Add a reference to the System.dll file to your project. To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. In the Add Reference dialog box, click System.dll, and then click Select.
    3. Click OK to add a project reference to the System.dll file to MyEXE.
  4. Import the System.Diagnostics namespace to your project: To do this, follow these steps:
    1. On the View menu, click Property Pages.
    2. In the left pane of the MyEXE Property Pages dialog box, click Imports.
    3. Type the following text in the Namespace text box, and then click Add Imports:

      System.Diagnostics

    4. Click OK to import the System.Diagnostics namespace to MyEXE.
  5. Add a module to your project to direct users to the Microsoft home page. To do this, follow these steps:
    1. On the Project menu, click Add Module.
    2. In the Add New Item - MyEXE dialog box, click Open. By default, Module1.vb is created.
    3. In the Module1.vb file, locate the following statement:
      Module Module1
    4. Add the following code after the Module Module1 statement:
      Sub Main()
         ' Open the Microsoft home page in your default Web browser.
         Process.Start("http://www.microsoft.com")
      End Sub
  6. On the Build menu, click Build MyEXE.
back to the top

Create a Setup Project

To create a Setup project, follow these steps:
  1. On the File menu, point to Add Project, and then click New Project.
  2. Under Project Types, click Setup and Deployment Projects.
  3. Under Templates, click Setup Project.
  4. In the Name text box, type MySetup. Click OK.
back to the top

Add the EXE File to Your Setup Project

To add the EXE file that you created in the "Create an EXE File" section of this article to your Setup project, follow these steps:
  1. In the File System Editor, click Application Folder.
  2. On the Action menu, point to Add, and then click Project Output.
  3. In the Add Project Output Group dialog box, click Primary output to select the primary output of MyEXE, and then click OK.
back to the top

Add a Custom Action to Run the EXE File

To add a custom action to run the EXE file that you added to your Setup project in the "Add the EXE File to Your Setup Project" section of this article, follow these steps:
  1. On the View menu, point to Editor, and then click Custom Actions.
  2. In the Custom Actions Editor, click Install.
  3. On the Action menu, click Add Custom Action.
  4. In the Select Item in Project dialog box, double-click Application Folder.
  5. Click Primary output from MyEXE (Active), and then click OK.
  6. On the View menu, click Properties Window to select the Properties window for the custom action that you added in step 5.
  7. To specify that your custom action is not a Microsoft .NET Framework ProjectInstaller class, change the value of the InstallerClass property to False.
back to the top

Verify That Your Application Works

  1. On the Build menu, click Build MySetup.
  2. Start Windows Explorer.
  3. Locate the Setup.exe file that you built in step 1.

    Setup.exe is located in the MySetup\Debug folder. The MySetup folder is where you created your Setup project in the "Create a Setup Project" section of this article.
  4. Run the Setup.exe file.
  5. In the MySetup dialog box, click Next three times to start installing MySetup on your computer.

    MySetup is installed on your computer and you are directed to the Microsoft home page in your default Web browser.
  6. On the Installation Complete page, click Close to quit your installation.
back to the top

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
back to the top

Modification Type:MinorLast Reviewed:5/23/2005
Keywords:kbCustomAct kbPDWizard kbIDEProject kbAppSetup kbsetup kbDeployment kbHOWTOmaster KB827018 kbAudDeveloper