We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

swilliams
Posts: 7
Joined: Wed Jul 03, 2013 12:45 pm

Single exe, multiple service instances?

I have an executable that can be installed as a Windows service.
It supports install/uninstall from the command-line.
I can run "myservice.exe /instance=0 /i" to install the "MyService0" service.
I can then run "myservice.exe /instance=1 /i" to install the "MyService1" service.
Likewise, "myservice.exe /instance=1 /u" will uninstall the "MyService1" service.

How can I configure an installer to handle this with the following assumptions?

The service executables are contained in a single feature.
Single copy of myservice.exe on the target computer.
Instance 0 is always installed.
User can choose to install (or not) instances 1-9.
User could choose the relevant instances by enabling a sub-feature for each instance, or with a custom dialog with a property for each instance (whatever will work)
When installer is run at a later time to modify or uninstall, the UI should reflect which instances were previously installed.
When installer is run at a later time to modify, the user should be able to install/uninstall instances.
The service names/display names/descriptions for each instance are well-known and could be hardcoded in the installer if necessary.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Single exe, multiple service instances?

Hi,

In order to achieve what you want you can follow the steps below:
- go in the Files and Folders page and add your "myservice.exe" file
- go in the Organization page and move it in its own feature
- go in the Dialogs page, create a new dialog and customize it appropriately (i.e. you can use 9 check boxes, one for every instance from 1 to 9)
- with the "Shift" keyboard button pressed copy the custom dialog in the "Maintenance" folder below the "CustomizeDlg" dialog
- the properties related to the 9 check boxes must be available in Maintenance mode so you can follow the solution described in the Install Parameters Not Persisted In Maintenance Mode thread
- go in the Custom Actions page and add a "Launch installed file" custom action for every instance of your service with the following configuration:
  • Installed File: myservice.exe
    Command Line: /instance=0 /i
    (another custom action for /instance=1 and so on)
- for all custom actions except the one related to "instance0" use the following settings on "Execution Stage Condition" group:
  • Check only: Install and Maintenance
    Condition: CHECKBOX_1
    (CHECKBOX_2 for instance2 and so on)
- create 10 more "Launch installed file" custom actions to uninstall the service:
  • Command Line: /instance=1 /u
    Check only: Uninstall and Maintenance
    Condition: (CHECKBOX_1 AND (REMOVE = "ALL" OR AI_INSTALL_MODE = "Remove")) OR (NOT CHECKBOX_1 AND ( Installed AND REMOVE <> "ALL" AND AI_INSTALL_MODE <> "Remove" ))
    (custom action related to "instance0" has no condition and "Maintenance" unchecked)
- build and run the project

The solution I described above tries to install an already installed instance on "Repair" or "Modify" mode (if their check boxes are still checked) and also tries to uninstall a service that is not installed, during uninstallation of the product. So, if this is not allowed by your service the scenario becomes more complicated.

I also attached a sample project with the steps described above already done. You can test it and let us know if this is what you want, otherwise give use more details about your scenario.

Best regards,
Eusebiu
Attachments
Single exe, multiple service instances.rar
(4.86 KiB) Downloaded 454 times
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
swilliams
Posts: 7
Joined: Wed Jul 03, 2013 12:45 pm

Re: Single exe, multiple service instances?

I've got it working with some changes. I only want to run the custom actions when required and not all the time. So, here's a summary of what I did. Instance 0 is tied to the executable install so it isn't tied to a checkbox. Some of the below is from Eusebiu, some from the install parameters link and some is mine.

Once:
Create a blank feature "Instance Management" under the service feature (not displayed, installed by default(same as service), always install locally(same as service))
Create a dialog "ChooseInstances" (copy after CustomizeDlg in various locations)
Modify MaintenanceTypeDlg
Per install parameters linked page, but "Reinstall one or more features" for feature "Instance Management"

Per instance:
Add registry search for the instance: "INSTANCE01"
Add a feature under "Instance Management" called "Instance 1" (Not displayed, not installed by default, install locally)
Move "INSTANCE01" registry search into feature "Instance 1" (change identifier to "Instance1")
Add custom action "Install_00" after "Finish Execution"
Command: "/instance=1 /i"
Condition: "(&Instance1 = 3) AND NOT (!Instance1=3)"
The custom action will only run when need to install feature and not yet installed
Add custom action "Uninstall_00" after "Preparing"
Command: "/instance=1 /u"
Condition: "(&Instance1=2) AND (!Instance1=3)"
The custom action will only run when need to uninstall feature and currently installed
Modify ChooseInstance dialog
Add checkbox for instance
Checkbox Value = "Install"
Checkbox default value = ""
Property name = "INSTANCE01" (added when you created the registry search with the same name)
Add Published Event
Event: Install one or more features locally
Argument: "Instance 1" (name of instance 1's feature)
Condition: INSTANCE01<>"" (property isn't blank, ie. "Install")
(Check the "Show entire condition" checkbox and only enter the above so that this event applies for install AND modify)
Add Published Event
Event: Install one or more features locally
Argument: "Instance 1" (name of instance 1's feature)
Condition: INSTANCE01="" (property is blank)
(Check the "Show entire condition" checkbox and only enter the above so that this event applies for install AND modify)

NOTES:
Registry search moved into each instance feature because blank features won't get installed.
It seems like I jumped through a lot of hoops. But, I wanted install/modify/uninstall to ALL work using the same properties, events, etc. (You know, DRY!)
Using "Show entire condition" for dialog - In my case, I didn't need different behavior for install/modify, so thinks makes maintenance easier.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Single exe, multiple service instances?

Hi,

I'm glad you got this working. Just let us know anytime you need help.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
swilliams
Posts: 7
Joined: Wed Jul 03, 2013 12:45 pm

Re: Single exe, multiple service instances?

An additional detail I just found...

The Uninstall custom actions need a more precise location.
In the custom actions installation sequence window, right-click any of the items and select Show Standard Action -> Preparing -> InstallValidate
Your uninstall actions needs to be placed between "Preparing" and "InstallValidate"

Why?
If one of the instance services is running and you perform a complete uninstall, InstallValidate will show the FilesInUse dialog complaining about that service (or services). With the new location for the actions, the service will already be stopped and removed before WindowsInstaller gets a chance to complain.
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Single exe, multiple service instances?

Hi,

Indeed, during the InstallValidate standard action the installer checks if any file is in use and if so, it displays the "FilesInUse" dialog. So, you can place your uninstall custom actions before "InstallValidate" standard action and everything should work fine.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”