Setup.EXE bootstrap for WiX and/or msi

Creating msi files using WiX is normally great, however one thing that is terrible is when you want your users to upgrade a product. Rather than simply selecting the msi they are required to issue

MSIEXEC /i My.msi REINSTALL=ALL REINSTALLMODE=vomus

Not exactly user friendly. So it was time to create a nice setup.exe bootstrap to detect when an upgrade was needed and issue the horror statement. A quick tour around the Windows SDK brought up the their sample. Written in Win32/C++ it seemed to be over complicated especially since I know the product is only ever going onto machines with .net pre-installed. So I wrote the following little csharp console code that does the trick for my requirements.

 

static

void Main(string[] args)

{

Type componentType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

if (componentType == null)

{

Console.WriteLine("Windows Installer is either not installed or could not be located");

return;

}

object componentInstance;

try

{

componentInstance =

Activator.CreateInstance(componentType);

}

catch (Exception e)

{

Console.WriteLine("Windows Installer is either not installed or could not be located: " + e.Message );

return;

}

 

object returnType = componentType.InvokeMember("Products", BindingFlags.GetProperty, null, componentInstance, null);

IEnumerable stringList = (IEnumerable)returnType;

bool foundProduct = false;

foreach (string product in stringList)

{

if (product == "{YOURPRODUCT_GUID}")

{

foundProduct =

true;

break;

}

}

if (foundProduct)

{

System.Diagnostics.

Process.Start(@"msiexec",

@"/i My.msi REINSTALL=ALL REINSTALLMODE=vomus");

}

else

{

System.Diagnostics.

Process.Start(@"msiexec", "My.msi");

}

}

 

Advertisements
This entry was posted in cSharp. Bookmark the permalink.

2 Responses to Setup.EXE bootstrap for WiX and/or msi

  1. briler says:

    how can i make the exe anf the msi to one exe?

    • pauliom says:

      If you feel the need then store the msi as a resource in the exe. When launched write it to temp and execute it. Not sure why you’d bother though?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s