Microsoft KB Archive/827018

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

Article ID: 827018

Article Last Modified on 4/12/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

-



IN THIS TASK

 * SUMMARY
 * Requirements
 * Create an EXE File
 * Create a Setup Project
 * Add the EXE File to Your Setup Project
 * Add a Custom Action to Run the EXE File
 * Verify That Your Application Works
 * REFERENCES



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:  Start Visual Studio .NET. Create a new Empty Project. To do this, follow these steps:  On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects. Under Templates, click Empty Project. In the Name text box, type MyEXE. Click OK. </li> Add a reference to the System.dll file to your project. To do this, follow these steps:  On the Project menu, click Add Reference.</li> In the Add Reference dialog box, click System.dll, and then click Select.</li> Click OK to add a project reference to the System.dll file to MyEXE.</li></ol> </li> Import the System.Diagnostics namespace to your project: To do this, follow these steps:  On the View menu, click Property Pages.</li> In the left pane of the MyEXE Property Pages dialog box, click Imports.</li> Type the following text in the Namespace text box, and then click Add Imports:

System.Diagnostics

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

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 &quot;Create an EXE File&quot; 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 &quot;Add the EXE File to Your Setup Project&quot; 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 &quot;Create a Setup Project&quot; section of this article.
 * 1) Run the Setup.exe file.
 * 2) 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.
 * 1) On the Installation Complete page, click Close to quit your installation.

back to the top

<div class="references_section">