How to prevent json modification while wix msi upgrading - wix

I am new to wix msi .I am using Wix to create msi for my window service .While installing msi, a json file will be created in installation folder with application details(using .net core). This file will be modified (recreating) while upgrading msi .I want to prevent json being modified on each msi upgrade.
I have tried couple of methods. But didn't get desired result.
1.Using custom action-
<Property Id="C_TEMP" Value="C:\Temp" />
<Property Id="ROBOCOPY_EXE">robocopy.exe</Property>
<CustomAction Id="CopyToTemp" Property="ROBOCOPY_EXE" Return="ignore" ExeCommand='"[INSTALLDIR]\Configuration" "[C_TEMP]\ServerSettings" AgentDetails.json' />
<CustomAction Id="CopyFromTemp" Property="ROBOCOPY_EXE" Return="ignore" ExeCommand='"[C_TEMP]\ServerSettings" "[INSTALLDIR]\Configuration" AgentDetails.json /MOVE /IS' />
<InstallExecuteSequence>
<Custom Action="CopyToTemp" Before="InstallInitialize">Installed AND (NOT REMOVE="ALL" OR UPGRADINGPRODUCTCODE)</Custom>
</InstallExecuteSequence>
using component
<Component Id="myconfig" NeverOverwrite="yes" Permanent="yes" >
<File Id="AgentDetails.json" Name="AgentDetails.json" KeyPath="yes" Source="$(var.BasePath)\AgentDetails.json" />
</Component>

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

WIX Uninstall Custom Action Error Code 2753

I'm having problems with a WIX CustomAction that I'd like to run when a user uninstalls an application.
Here's my XML
http://schemas.microsoft.com/wix/2006/wi'>
<Package Description='pak' InstallerVersion='200' Compressed='yes' />
<Media Id='1' Cabinet='setup.cab' EmbedCab='yes' />
<Property Id='ARPSYSTEMCOMPONENT'>1</Property>
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id="TempFolder">
<Directory Id="INSTALLLOCATION" Name="~_tmpdir">
<Component Id='MyComponent' DiskId='1' Guid=''>
<File Id="File0" Name="Runtime.exe" Source="Runtime.exe" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id='InstallFeature' Title='Install Feature' Level='1'>
<ComponentRef Id='MyComponent' />
</Feature>
<CustomAction Id="RunInstall" Return="ignore" Execute="deferred" FileKey="File0" ExeCommand="Runtime.exe" HideTarget="no" Impersonate="no" />
<CustomAction Id="RunUninstall" Return="ignore" Execute="deferred" FileKey="File0" ExeCommand="Runtime.exe" HideTarget="no" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="RunInstall" Before="InstallFinalize">NOT REMOVE~="ALL"</Custom>
<Custom Action="RunUninstall" Before="InstallFinalize">REMOVE~="ALL"</Custom>
</InstallExecuteSequence>
The Runtime.exe launches as expected when installing the application but when I uninstall I get an error "The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2753".
Looking at the event viewer sheds a little more light on the problem, it contains the following "The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2753. The arguments are: File0, , ".
So, it seems like it can't find Runtime.exe but I'm not sure why. The file is bundled into the MSI and it runs on install but I can't work out why it doesn't run on uninstall.
Many thanks
You should sequence the uninstall custom action earlier. "Before InstallFinalize" is very late, and almost certainly results in attempting to run the program after RemoveFiles has deleted it, hence the error. Look at the InstallExecuteSequence in your MSI file and see where RemoveFiles is relative to your CA and InstallFinalize. You may need to be before StopServices and other actions that remove registry values, depending on how much of the installed product your code needs. Or run it from the Binary table (beware of dependencies) if it really needs to be literally just before the uninstall completes.

Wix: condition on property not working

I have a util:RemoveFolderEx element that I only want to run when the program is being uninstalled. I put it inside its own component then set up a condition on a property as to whether it should be included.
Can anyone explain to me why the following doesn't work?
<Property Id='UNINSTALLMODE' Value="FALSE"></Property>
<DirectoryRef Id="DATADIR">
<Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
<util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
<Condition>(UNINSTALLMODE="TRUE")</Condition>
</Component>
</DirectoryRef>
<CustomAction Id="CA.SetUninstallMode" Property="UNINSTALLMODE" Value="TRUE" />
<InstallExecuteSequence>
<Custom Action="CA.SetUninstallMode" Before="WixRemoveFoldersEx" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
I've checked the logs and the custom action correctly sets UNINSTALLMODE to "TRUE" when uninstalling the software. On install and reinstall it is "FALSE". I've tried the custom action to be scheduled Before="WixRemoveFoldersEx" and Before="CostInitialise" which are relevant to the RemoveFoldersEx.
Any help is much appreciated, this is driving me nuts! Neil
EDIT: I updated the wix to this
<Property Id='P.INSTALLMODE' Value='0'></Property>
<Property Id='P.UNINSTALLMODE' Value='0'></Property>
<DirectoryRef Id="DATADIR">
<Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
<util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
<Condition>(P.INSTALLMODE = 1) OR (P.UNINSTALLMODE = 1)</Condition>
</Component>
</DirectoryRef>
<CustomAction Id="CA.SetInstallModeToTrue" Property="P.INSTALLMODE" Value='1' />
<CustomAction Id="CA.SetUninstallModeToTrue" Property="P.UNINSTALLMODE" Value='1' />
<InstallExecuteSequence>
<RemoveExistingProducts Before="InstallInitialize" />
<Custom Action="CA.SetInstallModeToTrue" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (NOT PREVIOUSVERSIONSINSTALLED)</Custom>
<Custom Action="CA.SetUninstallModeToTrue" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
The custom actions run immediately after the DATADIR value is read from the registry and before the CostInitialize.
Here is what happens in the following situations
Install -> condition is met and the component is installed
Reinstall -> condition is not met but the component is still uninstalled then reinstalled
Uninstall -> condition is met and the component is uninstalled
All I can take from this is that the condition is only applicable for the installation procedure and once a component is installed it is not possible to impose a condition on it for being removed.
EDIT2: Finally got this working by using a property for the removefolderex which is set by a custom action. Seems simple now.
<Property Id='P.REMOVEDATAFOLDER' Secure='yes' />
<DirectoryRef Id="DATADIR">
<Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
<util:RemoveFolderEx On="uninstall" Property="P.REMOVEDATAFOLDER" />
</Component>
</DirectoryRef>
<CustomAction Id="CA.SetDataFolder" Property="P.REMOVEDATAFOLDER" Value='[DATADIR]' />
<InstallExecuteSequence>
<Custom Action="CA.SetDataFolder" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
The condition of the component, which holds the RemoveFolderEx element, is False on install. This means the component is not installed. If it's not installed, it obviously won't be uninstalled, either. Hence, even if the condition-driving property is True on uninstall, the CA won't run because the component it depends upon was not installed.

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"