Custom Action for Feature in WIX - wix

I am trying to execute an EXE file through my installation and this file should be installed if the related feature will be installed in the feature tree.
I have two questions :
1-How to relate the Custom Action to this feature."The condition"
2- How I can include this exe file in the generated file. "This EXE File is a SQL Installation which I already made in WIX BOOTSTRAPPER "
http://apprize.info/web/wix/13.html
and my code is
<Feature Id="SubFeature1" Title="SQL Installation" Level="1" >
<ComponentRef Id="SubComponent1"/>
</Feature>
<Feature Id="SubFeature2" Title="Second Subfeature" Level="1" >
<ComponentRef Id="SubComponent2"/>
<!-- <Condition Level="0">IISMAJORVERSION=""</Condition> -->
</Feature>
</Feature>
<CustomAction Id="CreateSQLINSTALLER" Directory="BMSS4_Installer"
Execute= "deferred" Impersonate="no" Return="ignore"
ExeCommand="[BMSS4_Installer]Sql_Installation_Test1.exe -install" />
<InstallExecuteSequence>
<Custom Action="CreateSQLINSTALLER" Before="InstallFinalize"><![CDATA[(&SubFeature1)]]></Custom>
</InstallExecuteSequence>
the Sql_Installation_Test1.exe is included in the main folder so BMSS4_Installer..
But is it right to use it direclty like that in Directory tag om CustomAction !!

Feature conditions are documented here:
https://msdn.microsoft.com/en-us/library/aa368012(v=vs.85).aspx
in the action state of the feature. Basically you use a condition such as:
&featurename=3
where 3 is INSTALLSTATE_LOCAL, as there in the documentation. There are limits on where the condition can be used, the main one being after CostFinalize.
It's not clear if you are installing some version of SQL itself, but that would have its own install and wouldn't need repackaging, and it would be a prerequisite installed with Burn, for example. If it's a separate MSI setup of yours, again a Burn package would probably be the best way to install it and your other MSI.

Related

Registering SharpShell extension using SRM via WIX installer

Firstly I should clarify that I am a novice and have been struggling to understand the WIX formatting, but by cobbling together examples found on-line, I now have the files installing fine so I next need to register my DLL.
I used the example here as a starting point: How to deploy a SharpShell-based shell extension via WiX? but it seems that the SharpShell tool srm.exe may not be getting called at installation.
If I manually call srm.exe as follows, it works as hoped i.e. the DLL is registered and my shell extension works.
srm install MyExtension.dll -codebase
I can also see that the registration has been successful via the Server Manager application that comes with SharpShell.
I can also manually uninstall with the following - not that this is particularly relevant to my problem but it at least confirms that the manual methods work:
srm uninstall MyExtension.dll
Here is a fragment of my WXS file. When I run the resultant MSI, the files are installed but the DLL is not being registered; confirmed via SharpShell's Server Manager. Where am I going wrong?
</Component>
<Component Id="SRMexe" Guid="C17BB61F-6471-46F9-AA87-2D14D2456632">
<File Id='srm' Name='srm.exe' DiskId='1' Source='..\MyExtension\packages\SharpShellTools.2.2.0.0\lib\srm.exe' KeyPath='yes'>
</File>
</Component>
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
</ComponentGroup>
</Fragment>
<Fragment>
<CustomAction Id="InstallShell" FileKey="srm"
ExeCommand='install "[INSTALLFOLDER]\MyExtension.dll" -codebase'
Execute="deferred" Return="check" Impersonate="no" />
<CustomAction Id="UninstallShell" FileKey="srm"
ExeCommand='uninstall "[INSTALLFOLDER]\MyExtension.dll"'
Execute="deferred" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="InstallShell"
After="InstallFiles">
NOT Installed
</Custom>
<Custom Action="UninstallShell"
Before="RemoveFiles">
(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
</Custom>
</InstallExecuteSequence>
</Fragment>
It doesn't look like you have any references to the Fragment with the CustomAction definitions so they are not linked into your final output MSI.
Add a CustomActionRef from your Product element to create the reference.

How to use selfextract files in a wix install

I am really new using WIX, my only experience to build a complete install was with INNO, and WIX has been decided the way to go for an MSI
The installation includes a bunch of examples and templates, 427 files, which seems crazy to enumerate even with an utility like HEAT.EXE
So we went for a self-extracting utility. WIX install includes this custom utility and the compressed cabinet file, and then that extracts files and folders via custom action.
Problem is when we try to delete the compressed file and the extractor utility. I haven't found the way to delete them after the extraction takes place. RemoveFile seems to not work, and deleting the file within the extraction utility fires the self-healing mechanism in every run of the application.
Leaving the files in the install is dangerous, it is 200MB and it would reset all the installed examples if user runs the self-extraction utility by accident.
If it is of use, the WIX snippet in charge of this is like that:
<Fragment>
<ComponentGroup Id="App_Files">
<Component Id="cmp_Files_Dat" Directory="INSTALLCOMMONFOLDER" Guid="{8BFED6C2-4D4F-48BB-xxxx-C171F624C90B}">
<File Id="fil_Files_Dat" Source="appfiles\files.dat" />
<RemoveFile Id="rem_Files_Dat" Name="files.dat" On="install" />
</Component>
<Component Id="cmp_UnpackFiles_exe" Directory="INSTALLCOMMONFOLDER" Guid="{5722B5E0-C6E8-4C71-yyyy-61EC0ACA0D72}">
<File Id="fil_UnpackFiles_exe" Source="appfiles\UnPackFiles.exe" Checksum="yes" />
<RemoveFile Id="rem_UnpackFiles_exe" Name="UnPackFiles.exe" On="install" />
</Component>
</ComponentGroup>
<CustomAction Id="action_UnPackFiles" FileKey="fil_UnpackFiles_exe" ExeCommand="[INSTALLCOMMONFOLDER]" Execute="commit" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="action_UnPackFiles" After="InstallFiles" > NOT (REMOVE="ALL") </Custom>
</InstallExecuteSequence>
</Fragment>
The net result of the code above leaves the files, does not remove them.
Thanks in advance
Josep

Files not installed when executing custom action in WIX

I am writing a WXS file for a package I want to install. For the sake of simplicity, let's say I want to install 1 file and then I want to execute a command against it (in my case, it is a public GPG key and I want to import it after the installation is done). Here are the relevant parts of my WXS file:
<CustomAction Id="ImportKey" Directory="INSTALLDIR"
ExeCommand="[SystemFolder]cmd.exe /C gpg --import keyfile.key"
Return="check" />
<!-- Install file keyfile.key into C:\GnuPG -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" Name="GnuPG">
<Component Id="GnuPGConfiguration" Guid="E9469F1C-A875-1014-A3B3-DEF3264B13C4">
<File Name="keyfile.key" Id="KeyfileKey" />
</Component>
</Directory>
</Directory>
<Feature Id="GnuPGConfiguration" Level="1" Title="GnuPG Configuration">
<ComponentRef Id="GnuPGConfiguration" />
</Feature>
<!-- Run custom action after files are installed -->
<InstallExecuteSequence>
<Custom Action="ImportKey" After="InstallFiles">NOT Installed AND NOT PATCH</Custom>
</InstallExecuteSequence>
I can successfully build the MSI. When installing, I use msiexec and turn on logging. There it says that installation fails on the custom action and the correct command is found in the log. Running it manually works. If I comment out execution of the command, the file is installed in the correct location (C:\GnuPG\keyfile.key exists after installation).
Instead of running my GPG command, I tried running dir ant redirected its output to a file. Viewing it, I can see that keyfile.key is not among the files in C:\GnuPG. It seems that the command is run before the file is installed.
Any ideas on what I am doing wrong?
You need to read and understand:
Installation Phases and In-Script Execution Options for Custom Actions in Windows Installer
You will find yourself considering needing
<CustomAction ... Execute="deferred" and Impersonate="no" ... />
Also you are likely to need to qualify the location of the .key file as your current directory isn't going to be what you think it is.

Add an option to enable or disable a feature during installation process using wix

Hi I have written code for my wix project such that it creates and deletes a schedule task on install or uninstall respectively. But I want to give the users an option(Feature) during installation where they enable or disable the task to get created not. My code so far shows the option but creates the task even when I select disable.
The feature level for your scheduled task is 1, your installlevel is going to be 1 or more, therefore this feature will always install. When your user selects an option it has to change the installlevel
Here is further info on features etc
here is your code in better formatting.
<Component Id='ScheduledTask' Guid='{ABDBFC55-F5DF-4DC9-92FF-DD9C7A5D4880}' KeyPath='yes'>
<File Source="../../apps/bin/Release/Swu.exe"></File>
</Component>
<Feature Id="SWUSchedTaskFeature" Title="Create a scheduled task" Level="1" Absent="allow" TypicalDefault="install" Description="Creates and configures Scheduled Task for the SWU application" Display="expand" AllowAdvertise="no">
<ComponentRef Id="ScheduledTask"/>
</Feature>
<InstallExecuteSequence>
<Custom Action="CreateScheduledTask" Before="InstallFinalize">
<![CDATA[&CreateScheduledTask=3]]>
</Custom>
</InstallExecuteSequence>

How to prevent a Windows user from being removed and created during a patch

I have a project that uses the WiX extension WixUtilExtension to create a user for our Windows services. When I patch the installation (using an .msp), the custom actions RemoveUser and CreateUser are executed.
I don't want these WiX extension created custom actions to run during a patch.
I can add a condition directly to the custom action (ConfigureUsers) in the InstallExecuteSequence table of the MSI to prevent this, but I have not found a way to handle this in WiX.
Using WiX, how can I prevent RemoveUser and CreateUser from being executed during a patch?
<util:Group Id="LocalAdministrators" Name="Administrators"/>
<DirectoryRef Id="INSTALLLOCATION" DiskId="1">
<Component Id="CreateServiceAccountUser" Guid="{614550A7-C766-4B5D-9BF9-233D07EB3B69}">
<util:User Id="ServiceAccountUser"
CanNotChangePassword="yes"
CreateUser="yes"
Disabled="no"
FailIfExists="no"
LogonAsService="yes"
Name="TestUser"
Password="testuserpw"
PasswordExpired="no"
PasswordNeverExpires="yes"
RemoveOnUninstall="yes"
UpdateIfExists="yes">
<util:GroupRef Id="LocalAdministrators"/>
</util:User>
<RegistryKey Root="HKMU" Key="Software\AMT\WebBrix">
<RegistryValue Name="CreateServiceAccountUser"
Value="Common"
Type="string"
KeyPath="yes" />
</RegistryKey>
</Component>
</DirectoryRef>
You can do that in WiX:
<InstallExecuteSequence>
<Custom Action='ConfigureUsers'
After='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
Here are some more conditions
Action run only during Install
Condition: NOT Installed AND NOT PATCH
Action only runs during removal of MSI
Condition: REMOVE
Action runs during Install and repair
Condition: NOT REMOVE
Action runs during Install and remove
Condition: There must be no condition
Action calls EXE installed by MSI
Condition:NOT Installed AND NOT PATCH
Run on initial installation only:
NOT Installed
Run on initial install or when repair is selected.
NOT Installed OR MaintenanceMode="Modify"
Run when being uninstalled from command line or add / remove menu.
REMOVE~="All" OR MaintenanceMode="Remove"