Question

After way too many experiments, I've come to the conclusion that Windows Installer is simply bad technology. But the customers want MSI files.

So, how can I create an MSI file that extracts an EXE file to a temporary directory and runs it with options same or similar as were passed to the EXE file?

Options to an MSI are explained in Msiexec (command-line options) (low level "run" of an MSI is msiexec option package.msi).

EDIT: mjmarsh's WiX solution looks like it works. I just haven't had a chance to try it yet (crunch time). If it works, I'll be accepting it.

EDIT: it does not work. Missing piece: attended/unattended does not seem to be available.

Anyway, the only to make this work at all would be for the custom action to kill its parent process!

EDIT: So somebody posted as a further answer wrapping the whole thing as a post-install custom action. Theoretically possible but since a reboot may be required (thanks MS for .NET 4 requiring a reboot sometimes) we have to do further hackery. So from the matrix of advantages:

Transparency: No. One big custom action.
Customizability: No.
Standardization: No. 
Management and reporting: No. Appears to work but will not.
Security: No benefit.
Validation: No. The hackery required to survive reboot makes this sure to not work.
Resiliency: Completely defeated.
Rollback: No. Rollback didn't work when we were using MSI anyway.
Patching & Updates: No. We have a local solution anyway.
Logging: No. Appears to work but will not.

No point.

Was it helpful?

Solution 4

No solution. We went NSIS as corporate MSI install is going to be broken anyway due to MSI nesting problem (just try installing EXE wrapping MSI from inside MSI someday).

OTHER TIPS

Well, there is the free way and the $$$ way. I cannot document everything here, but this should get you started.

On a side note, yes, Windows Installer is a maddening technology. There are many times where I think a task will be straightforward, but it actually becomes complicated. You definitely have to immerse yourself to understand it.

In any case, here goes:

Free: WiX (here)

This is a free tool to generate MSI files from a set of XML configuration files. I'll leave you to find tutorials online, but here is the crux:

You can compress your EXE into the installer by using the following tag in the WXS file:

<Binary Id="MYEXE" src="<path to my exe?"/>

Then you can create a custom action which launches your EXE file:

<CustomAction Id="EXECA_CALLMYEXE" Return="check" Execute="deferred" BinaryKey="MYEXE"
      ExeCommand="my command line"/>

Then you insert your custom action into the InstallExecuteSequence in the appropriate spot (I almost always run mine somewhere between InstallInitialize and InstallFinalize)

<InstallExecuteSequence>
   <Custom Action="EXECA_CALLMYEXE" After="InstallInitialize"><![CDATA[Not REMOVE]]></Custom>

$$$: Get InstallShield (HERE)

First create a "Basic MSI" project and make sure you say you want no setup.exe generated. You set this in the Release settings.

Then you essentially do the same thing as with WiX, but you have a UI for it.

  • You can specify your helper EXE file by using the Direct Editor and putting your EXE file in the 'Binary' table
  • You can create a custom action to launch that EXE file from the "Custom Actions" Node in the tree on the left
  • You can insert the custom action by selecting "Install Sequences" and putting it in the InstallExecuteSequence somewhere between InstallInitialize and InstallFinalize as I said before.

Sorry, I could not be more detailed, but this should be a good start.

I think the easiest way to create a .MSI file is to use WiX.

Lesson 1 from the WiX tutorial is all you need to create a simple install.

Joshua, I understand your frustration very well. MSI is quirky to say the least - a completely new way to think of deployment. Still, applied correctly MSI offers the best possible deployment, especially for corporate customers.

What operations does your installer EXE perform? Is it largely file copy, some COM registration and some registry writes, or does it run complex installation logic, setting up databases etc...? The reason I ask is because it probably would be very quick to create a well functioning WIX MSI for you so you can abandon the EXE approach.

It is indeed possible to run an EXE from inside an MSI, but it requires proper sequencing, and it is guaranteed to cause you more blues than a simple MSI. If the app is small, and not doing anything crazy during installation, I would be happy to provide you with a basic WIX conversion.

There is also a free version of the MSI Wrapper. It also supports uninstall and upgrades. Also, it only creates one entry in the Add or Remove programs.

Adding to weir's answer, change the custom action attribute like below:

<!--Run Action-->
    <CustomAction Id="RunWrappedExe"
                  Return="asyncNoWait"
                  FileKey="ApplicationFileId"
                  Execute="deferred"
                  ExeCommand=""
                  HideTarget="no"
                  Impersonate="yes"/>

Setting Return=asyncNoWai does not wait for the exe to return. The installer does it's job and closes normally. Meanwhile, the exe continous its execution.

-Madhuresh

If you don't want to manage MSI, but only execute EXE, try Exe to MSI Converter Free. You just put in the path to the EXE and get an MSI.

try this:

In MSI package, there is a behaviour call "Launch an application after installation", that means your exe file will be executed after the MSI installation(the MSI is closed).

Try to execute your exe there, so when your exe invoke other MSI packages, it won't conflict with the first one.

Wix can do it. Here is my sample code for wix 3.5:

<?xml version='1.0'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
   <Product Id='*' UpgradeCode="11111111-2222-3333-4444-555555555555" 
        Name='My Setup' Language='1033' Version='1.0.0.0' 
        Manufacturer='Your company'>

    <Package Description='pak' InstallerVersion='200' Compressed='yes' />

    <Media Id='1' Cabinet='setup.cab' EmbedCab='yes' />

    <Directory Id='TARGETDIR' Name='SourceDir'>
        <Directory Id="TempFolder">
            <Directory Id="INSTALLLOCATION" Name="~_tmpdir">
                <Component Id='MyComponent' DiskId='1' Guid=''>
                    <File Id="File0" Name="setup.exe" Source="setup.exe" />
                    <File Id="File1" Name="file1.txt" Source="file1.txt" />
                </Component>
            </Directory>
        </Directory>
    </Directory>

    <Feature Id='InstallFeature' Title='Install Feature' Level='1'>
        <ComponentRef Id='MyComponent' />
    </Feature>

    <!-- Run Action -->
    <CustomAction Id="RunWrapExe" Return="ignore" Execute="deferred" 
                  FileKey="File0" ExeCommand="setup.exe param here"  
                  HideTarget="no" Impersonate="no" />

    <InstallExecuteSequence>
        <Custom Action="RunWrapExe" 
                After="InstallFiles">NOT REMOVE~="ALL"</Custom>
    </InstallExecuteSequence>

   </Product>
</Wix>

I was having the same problem (wrap EXE, call other MSI from the EXE including .net setup, etc.), and here is my solution:

I build the setup exe using InstallAware. It has its own MSI Wrapper that wraps the generated EXE with MSI.

It works OK, the EXE can call other MSIs without any problem (including .net setup, other 3rd party setups), but that is because the launching MSI ends ("returns") rights after it launches the setup EXE file, and that way they avoid the MSI limitation of recursive MSI calls.

BUT - some customers (companies) that uses MSI deployment tools, requires the MSI (msiexec) to return (end) only after the setup process ends, and that is a problem with the above solution.

So - to solve this:

There is another MSI Wrapper (exemsi.com) that generates MSI that returns only after the EXE setup ends, but for using that you must use another unique option of InstallAware:

InstallAware has the option to generate the EXE setup using their own native engine, and not based on Windows Installer engine, to avoid MSI recursive limitation. Combine those both, and you have the perfect solution.

Hope this will help someone, although many years passed since this question was first posted.

Simple trick:

Project image

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Setup
{
    internal class Program
    {
        [DllImport("kernel32.dll")]
        private static extern IntPtr GetConsoleWindow();

        [DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private static void Main(string[] args)
        {
            ShowWindow(GetConsoleWindow(), 0);
            Stream st = Assembly.GetExecutingAssembly().GetManifestResourceStream("Setup.MSI.Temp.msi");
            string path = Path.Combine(System.IO.Path.GetTempPath(), "Temp.msi");
            using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                st.CopyTo(fileStream);
            }
            Process p = new Process();
            p.StartInfo.FileName = path;
            p.Start();
            p.WaitForExit();
            File.Delete(path);
        }
    }
}

I made a simple and free .NET tool to create MSI from exe or folder (it’s using wixsharp and wix) http://legacy.averbouch.biz/free-msi-wrapper

screenshot

Nah man, just use Inno Setup's wizard. It makes an setup EXE but not an MSI. It's like 5 mins and you'll have a windows installer.

Simply download it, install it, point it to your EXE, and follow the on-screen prompts

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top