Blog Archives

C# Create a Windows Installer Class Custom Action bootstrap DLL in .Net

The standard windows installer project included with Visual Studio right out of the box is great in many deployment scenarios.

For more advanced needs, organizations and developers usually defer to 3rd party solutions, such as InstallShield, Wise, wix or NSIS (NullSoft).

These solutions are all very well tested and have minimal learning curve in a lot of cases. However, if you are tight on budget or simply looking for the experience and full customization, you can also create your own custom action installer class in Visual Studio.

Simply create a new DLL project included in the same solution as your windows installer project. From the Windows Installer Project go to “File System” and in your Application Folder add “Project Output” and select your new DLL. Now go to the “custom actions” tab and under install and/or uninstall right click and “Add Custom Action” then select the output under Application Folder. That’s it!

Make sure the class for your DLL has “RunInstaller” attributes and looks similar to the snippet below. You may also want to do some light reading on the “CustomActionData” property to see if there are any variables you may need such as “ProductCode”.

To change the custom action data property, from the custom action tab simply select your DLL output after adding it, and expand the Visual Studio Properties tab on the side.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace MSIBootstrap
    public partial class InstallHelper : Installer
        public static string InstallTitle = "Discount Notes"; //used by install/uninstall to get window handle
        public InstallHelper()

        public override void Install(System.Collections.IDictionary stateSaver)
try {
//your custom code
catch (Exception ex) {
throw new InstallException(ex.ToString());

 public override void Uninstall(System.Collections.IDictionary stateSaver)
//mimic same try/catch design pattern if you like

With this approach, you are essentially using the standard windows installer project to bootstrap your custom action DLL.

This is very powerful, and allows you to define your own code logic and conditions as well as custom interfaces and forms designed directly from within Visual Studio.

Wise installer,
wix installer,
Nullsoft NSIS,
Wikipedia (bootstrapping),,, (persisting savedState),
MSDN, “CustomActionData”,


Remove Repair Option from Custom Windows Installer

This technically can be done in various ways relating to InstallShield, Wise, WiX, NSIS or other installer platforms, but generally speaking is the same concept all throughout whether you are using third party tools or creating your own bootstrap/windows installer project/custom action.

An MSI file contains tables of data. Within these tables, there is one labeled “property” which contains a series of string/value items. The properties which control visibility of repair/modify in button are referred to as:


In order to modify the MSI tables and change these properties you must first be able to modify the MSI file. This can be done one of two ways:

Option 1:
Download and install the Windows SDK Components for Windows Installer Developers.

Once downloaded and installed, navigate to “\Program Files\Microsoft SDKs\Windows\v7.0\Bin” and run “Orca.msi” to begin the install for orca.

Once installed, run orca and open the propery table and add an entry for ARPNOREPAIR and set its value to 1.

Option 2:

As an alternative, unless you have some other reason for DLing the SDK, you can totally bypass the 2.5GB DL just for a little orca file by using an awesome proprietary tool called SuperOrca :).

SuperOrca IMO is much improved over the basic MS orca, but the end result is the same. Open the MSI, navigate to PROPERTY table, and add the entry with a value of 1, save, test.

For C++ or custom action programmers, you can call MsiSetProperty and pass in ARNOREPAIR for the name and 1 for the value for the same end result.

MsiSetProperty and MsiGetProperty cannot be called from your typical C# installer class/bootstrap DLL, since the handle to the installer is never passed in.

For a little background history, in my particular case, a custom action in the installer is targeting a DLL I created (separate project in the same solution). This DLL inherits the installer class and overrides the install and uninstall methods.

MSDN (Windows Installer SDK),,
SuperOrca (Pantaray),
MSDN (msisetproperty),
MSDN Blogs (msisetproperty,getproperty),
MSDN (create a custom action),

Create an Uninstall Shortcut for Windows Installer in C#

When utilizing the windows installer project type bundled with Visual Studio I was very surprised to find there was no simple functionality to add an uninstall shortcut.

Instead, there are a few workarounds, some better than others but overall going to have to get your hands dirty to make this one work.

Option 1 – Batch File

Create an uninstall batch file and add a shortcut which points to the batch.

Only downside of this solution, which is actually the simplest, is an ugly little bugger we all know as the DOS window pops up when you execute the batch.

(courtesy of

@echo off
msiexec /x {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

Option 2 – VBS File

No code example for this option since I didn’t even consider trying this one personally, but this would be to create the equivalent of the code above using WshShell in vbscript (which is actually a similar end result as the code in option 3).

The .vbs file would execute cleanly without a DOS prompt, but my experience with .vbs files has found that they are not AntiVirus friendly and don’t always port OS’es cleanly either. Certain API calls slightly change over time and can break syntax, and you never know if John Doe’s newest antivirus update will flag your .vbs file and prevent it from executing.

Option 3 – Roll up those sleeves

Create a separate app which calls msiexec either by instantiating a hidden cmd.exe process window, or calling it directly also using process object. Then add this separate app to your deployment project solution and create a shortcut in the installer which points to the primary output of your separate app project.

Using this method is the most work, but the best end result for the consumer IMO (isn’t that usually how it works? :P). If you wanted, you could even create your own uninstall process and run msiexec in “unattended” a.k.a “silent” mode and uninstall your app quietly in the background.

(courtesy of

using System.Diagnostics; //namespace containing process RD

public partial class App : Application
  void Application_Startup(object sender,StartupEventArgs e)
    for(int i = 0;i != e.Args.Length;++i)
      if(e.Args[i].Split('=')[0].ToLower() == "/u")
        string guid = e.Args[i].Split('=')[1];
        string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
        ProcessStartInfo uninstallProcess = new ProcessStartInfo(path+"\\msiexec.exe","/x "+guid);

Keep in mind in all of these scenarios, the application guid is necessary to pass as a parameter to msiexec. To pass this variable you will need to specify the productcode as a parameter in custom action data.

Such as:

CustomActionData => /productcode = [ProductCode]

I believe [ProductCode] may also be case sensitive, as I had originally specified “PRODUCTCODE” in one of my installers but this did not seem to pass through..


If you’re still reading by this far (and yes I tried to blow up however to draw your eyes), keep in mind your uninstall executable or batch is calling msiexec, not the other way around, so “ProductCode” is not yet part of the mix.

I’ve yet to find the cleanest solution to this final issue, but overall my thoughts would be to pass product code through to a different separate application added to your deployment project solution as part of the install process, and have this application either store the product code in a generic location such as:


…or, still using your “install helper” application, store it somewhere in the application directory in program files created by the installer. Essentially the same thing as application data, just leaves less chance of any traces of your program being left behind on uninstall.

Enjoy. 😉

Windows Installer (Relevant links for Custom Actions),,,,,
MSIexec command line options,
Flexera Software,