Package a .exe file with in a msi file

Any pointers to package a .exe file within a .msi file ?

When I click the .msi file it should execute the .exe file (which is inturn packaged within the .msi file).

Would love to do this in a programmatical way. Or any ideas to do the same in non-programmatic ways are also welcome :)

Upvotes: 0

Views: 830

Answers (2)

Barmak Shemirani
Barmak Shemirani

Reputation: 31599

Make a separate program called "self_extracting.exe", copy the installation file in to resource section of self_extracting file.

When you run "self_extracting.exe", it will extract "main.msi" from its own resource and copy it to hard disk. "self_extracting.exe" will then execute "main.msi" from hard disk.

This is an example in c#
Self-extracting Installer

Above example is perhaps over complicated. Here is a simple example to do this with WinAPI:

Create C++ Win32 project.

Add this line to *.rc file:

1 RCDATA "path_on_my_computer.msi"

When you build the project, *.msi file will be written to resource section. If *.msi file changes, compile the resource file again.

You have one *.cpp file as follows:

#include "stdafx.h"//if using precompiled headers
#include <windows.h>
#include <fstream>

int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int)
{
    HRSRC hrsrc = FindResource(0, MAKEINTRESOURCE(1), RT_RCDATA);
    if (!hrsrc) return 0;

    HANDLE hglob = LoadResource(0, hrsrc);
    if (!hglob) return 0;

    unsigned int size = SizeofResource(0, hrsrc);
    if (size <= 0) return 0;

    void *ptr = LockResource(hglob);

    wchar_t* setup_file = L"path_on_user_computer.msi";
    std::ofstream f(setup_file, std::ios::binary | std::ios::out);
    f.write((char*)ptr, size);
    f.close();

    ShellExecute(0, 0, setup_file, 0, 0, SW_SHOWNORMAL);

    return 0;
}

In release mode, go to "Project Properties" -> "Code generation" -> "Run time library", and select "Multi-threaded (/MT)" so the *.exe file can run without dependencies.

Upvotes: 1

Bogdan Mitrache
Bogdan Mitrache

Reputation: 10993

You can do this very easily with Advanced Installer, there is a tutorial convert EXE to MSI which actually creates an MSI wrapper over you EXE.

No coding is required.

You can place multiple EXE installers in this wrapper, to chain their execution. Also, for each EXE you can pass command line switches to make their installation silent (if the EXE supports such switches), thus you can obtain an MSI that supports full automatization to install you EXEs.

Upvotes: 1

Related Questions