Reputation: 68
I have searched and searched and tried so many 'solutions', including several here on SO, but none appear to be working.
We have a Topshelf Windows Service written in C# that I have been tasked with creating an installer for in the form of a WiX .msi that will be installed via the command line with a Service Account and Password passed in as arguments.
So far I have added the following properties:
<Property Id="SERVICEACCOUNT" Admin="yes" />
<Property Id="PASSWORD" Admin="yes" />
These are then assigned during the installation of the service:
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="MyServiceName"
DisplayName="My Service Display Name"
Description="My Service Description"
Account="[SERVICEACCOUNT]"
Password="[PASSWORD]"
Start="auto"
ErrorControl="normal" />
<ServiceControl Id="ServiceController"
Name="MyServiceName"
Remove="both"
Stop="both"
Wait="yes" />
With the Product.wxs in this state I can successfully install, update and uninstall the service from the command line:
msiexec.exe /i "C:\MyApplication.Installer.msi" SERVICEACCOUNT="domain\serviceaccount" PASSWORD="password"
Not supplying the SERVICEACCOUNT or PASSWORD fields defaults to install the service under LocalAccount which I need to avoid so I wrote a condition to validate that the parameters are always supplied on install:
<Condition Message="SERVICEACCOUNT and PASSWORD must be supplied">(SERVICEACCOUNT AND PASSWORD) AND NOT Installed</Condition>
This works - it displays a message box and terminates the installation if the parameters are not supplied or if the .msi is run directly from a double-click.
The problem then comes with upgrading and uninstalling as even though the condition states that it is only when "NOT Installed" when uninstalling, or mid-way through the upgrade the message box comes up (even if the .msi is called from the command line with the parameters supplied).
I have tried various permutations of the condition from other posts I have found that have reported success such as:
(SERVICEACCOUNT AND PASSWORD) AND NOT (WIX_UPGRADE_DETECTED OR UPGRADINGPRODUCTCODE) AND NOT (REMOVE="ALL")
and I have also poured over this cheatsheet, but to no avail.
Can anyones see what I am doing wrong or have any working examples of how to get a condition to validate ONLY when performing an installation? For all the logic behind the conditions, none of them appear to work as expected (or at least as I expect them to!)
Many thanks in advance.
Upvotes: 2
Views: 793
Reputation: 4798
Try
<Condition Message="SERVICEACCOUNT and PASSWORD must be supplied">(SERVICEACCOUNT AND PASSWORD) OR Installed</Condition>
This should stop fresh installs that don't have (SERVICEACCOUNT AND PASSWORD) but won't stop upgrades or uninstalls.
NOT Installed
represents the current MSI is not installed. When you upgrade, the msi detects the currently installed product and will run that msi with UPGRADINGPRODUCTCODE set. When the msi is run with UPGRADINGPRODUCTCODE it is uninstalling itself but it has Installed set so your condition will always fail in this case.
The same happens when you try to uninstall. Installed
is set during the start up of the msi so your condition would fail.
Generally with any conditions you want to happen on Installs but not on uninstalls/removal during upgrade, you can append "OR Installed" to your condition so that it will always be true on uninstalls.
Upvotes: 3