Skip to content

Create a MSI with multiple instances

Volker Berlin edited this page Feb 8, 2016 · 5 revisions

By default a MSI installer can installed only once. If you try to install a second instance then this is like an update and the previous installation will be removed. If you want create a multiple instances MSI installer with WIX toolset then it is very complicated.

Multiple instances

With Gradle and SetupBuilder this is very easy. You need only to set the count of possible instances in the msi task:

msi {
    multiInstanceCount = 100
}

This set the count of possible instance installations. The default value is 1. A limit is required because on creation time some GUIDs must be created.

The uninstaller in Programs and Features will be named like the installation directory. If the first instance is installed in the default location C:\Program Files\MyApp then the uninstaller is named MyApp. If the second instance is installed in C:\Program Files\MyApp 2 then the uninstaller is named MyApp 2.

Naming Rules

If you need different naming rules then you need to set your own multiple instances script with:

msi {
    multiInstanceScript = "${projectDir}/MultiInstance.vbs"
}

The default script can you use as basis.

Shortcuts and services

If you install different instances then the shortcuts and service must have also different names. For a service you must change the id and the displayName. You can do this with placeholders like:

setupBuilder {
    // declare a service for all platforms
    service {
        id = "MyService"
    }
 }
 msi {
     doFirst { 
         // patch the service for the instance only for Windows
         setupBuilder.services[0].displayName = '[ProductName] Server'
         setupBuilder.services[0].id = '[ProductName]'
         // create a shortcut on Windows platform with placholder
         setupBuilder.desktopStarter {
             displayName = '[ProductName]'
             executable = "MyApp.exe"
         }
     }
 }