Launching unmanaged applications with ClickOnce

The question came up from several attendees at my MSDN Webcast on ClickOnce yesterday:

“Can I launch a XXX application using ClickOnce?” (fill in XXX with VB6, MFC, etc. – non-.NET applications)

The answer is yes, you will just have to employ a little trick.

What you need is a simple little launcher application that IS a Windows .NET application. So do the following:

  1. Create a new Windows Application project with VS 2005.

  2. Delete the Form1 from the project.

  3. Add the unmanaged EXE and any supporting files to the VS 2005 project, which makes them part of this application from a ClickOnce perspective. As a result, they will get deployed with this application to its cache folder and can be executed by this launcher app.

  4. Edit the Program.cs file Main method and delete the current method body (which launches the application and the form) and replace it with code to launch the unmanaged executable. This just requires a single line of code: Process.Start(“MyUnamangedApp.exe”);

Note: You will need to give the launcher app full trust in the ClickOnce security settings.

Note2: If the unmanaged app relies on ActiveX or COM objects, those need to be added to the project as well, and you will need to add a reference to the COM DLL’s to the project to get their reg-free COM information added to the manifest. See this article for more details.

You can download a sample implementation here.