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");}
}
how can i make the exe anf the msi to one exe?
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?