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.
Related
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 newbie here. I'm curious if this approach is possible using WiX.
Problem statement...
I am packaging some SQL files that I want to execute against some parameters that the user will enter at run time. Think connection string information. One of the parameters that the user can enter is the directory where they want the DB to be installed.
Current solution (doesn't work).....
To do this i'm packaging these files using heat. When it sucks in this files one of my SQL files has some tokens in them that a custom action looks for to basically do a find replace in the file. The problem is thatwhile it is indeed doing a find replace it's doing them against the source files that heat sucked in and not the files that exist in the .msi file.
Question 1...
Within the WiX workflow is there a way that via a custom action I can do processing on the files that are stored within the .cab or .msi file? If that is possible can someone show me an example of this?
Question 2 . . .
If question 1 isn't possible the other idea I had was to break the find replace SQL piece and the file install piece into separate msi file. So the first step would be to explode all the files I need into the install directory via one msi. The next msi would execute the SQL piece as at that point the files exist on the file system for me to do editing on. Does this sound like a sane approach to the problem? It could very well be that I'm trying to work around WiX and not with WiX here.
Current code snippets
<Product>
<!-- This is where this will be installed-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLFOLDER" Name="ZOLLData">
<Directory Id="SQLINSTALLFOLDER" Name="Sql" />
</Directory>
</Directory>
<!-- CUSTOM ACTION DEFINITIONS-->
<CustomAction Id="FindReplaceZEDSTextCA"
Return="check"
BinaryKey="GemstoneInPremiseInstallerCustomActions.CA.dll"
Execute="immediate"
DllEntry="FindReplaceText" />
<!-- Database Information-->
<util:User Id="SQLUser" Name="[SQLUSERNAME]" Password="[SQLPASSWORD]"/>
<sql:SqlDatabase Id="MasterDatabase" Database="master"
Server="[SQLSERVERNAME]"
User="SQLUser"/>
<InstallUISequence>
<Show Dialog="SqlConnectionDlg" After="CostFinalize" />
<Show Dialog="ProgressDlgCustom" After="SqlConnectionDlg"/>
</InstallUISequence>
<InstallExecuteSequence>
<Custom Action="FindReplaceZEDSTextCA" After="InstallFiles">
</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<DirectoryRef Id="INSTALLFOLDER" />
</Fragment>
<Fragment>
<ComponentGroup Id="SqlComponents">
<Component Id="CreateDatabase.sql" Directory="INSTALLFOLDER" Guid="6A2C6088-9302-451C-A01B-02D618D4AC27">
</Component>
</ComponentGroup>
</Fragment>
Thanks in advance.
The problem was the my custom action was set with Execute="immediate". This should have been Execute="deferred".
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.
I am wanting to install files during a wix install conditionally whether a command line parameter has been set
e.g. I have the following file, which only installs if a DEBUG flag has been set
<Component Id="file.pdb" Guid="SOME-GUID">
<Condition>DEBUG</Condition>
<File Id="file.pdb" Source="file.pdb" KeyPath="yes" Vital="no" />
</Component>
I have added the DEBUG property and read it in from the command line. The File never installs though, I am perplexed as to why?
Solved the issue. Below is an explanation of what I was doing wrong and what I did to solve it
I had created an installer (.msi) and was using the following cmd line args to start it up
msiexec -i prog.msi DEBUGPROPERTY=True
I had several merge modules with components which would install depending on whether this property was set which were getting the property injected into them like so...
<Merge
Id="SomeID"
Language="1033"
SourceFile="Module.msm"
DiskId="1">
<ConfigurationData
Name="debugProperty"
Value="[DEBUGPROPERTY]" />
What I was missing was in the merge modules (.msm) i needed the following code
<Configuration Name='debugProperty' Format='Text' DefaultValue='[DEBUGPROPERTY]'/>
<Substitution Table='CustomAction' Row='setDebugProperty' Column='Target' Value='[=debugProperty]'/>
<CustomAction Id='setDebugProperty' Property='DEBUGPROPERTY' Value='[DEBUGPROPERTY]'/>
<InstallExecuteSequence>
<Custom Action='setDebugProperty' Before="LaunchConditions">1</Custom>
</InstallExecuteSequence>
This allowed me to access the property DEBUGPROPERTY inside this module so i could restrict whether a file was installed at install time or not, like so
<Component Id="File.pdb" Guid="SOME-GUID">
<Condition>DEBUGPROPERTY</Condition>
<File Id="File.pdb" Source="File.pdb" KeyPath="yes" Vital="no" />
</Component>
This now works, and allows me to install .pdb files during an install if i include this argument.
I want my msi installer to generate a set of folders in a particular location and put a dummy file in each directory.
Currently I have the following CustomActions:
<CustomAction Id="SMC_SetPathToCmd" Property="Cmd" Value="[SystemFolder]cmd.exe"/>
<CustomAction Id="SMC_GenerateMovieFolders" Property="Cmd" ExeCommand="for /f "tokens=* delims= " %a in ([MBSAMPLECOLLECTIONS]movies.txt) do (echo %a)" />
<CustomAction Id="SMC_CopyDummyMedia" Property="Cmd" ExeCommand="for /f "tokens=* delims= " %a in ([MBSAMPLECOLLECTIONS]movies.txt) do (copy [MBSAMPLECOLLECTIONS]dummy.avi "%a"\"%a".avi)" />
These are called in the InstallExecuteSequence:
<Custom Action="SMC_SetPathToCmd" After="InstallFinalize"/>
<Custom Action="SMC_GenerateMovieFolders" After="SMC_SetPathToCmd"/>
<Custom Action="SMC_CopyDummyMedia" After="SMC_GenerateMovieFolders"/>
The custom actions seem to start, but only a blank command prompt window is shown and the directories are not generated.
The files needed for the customaction are copied to the correct directory:
<Directory Id="WIX_DIR_COMMON_VIDEO">
<Directory Id="MBSAMPLECOLLECTIONS" Name="MB Sample Collections" />
</Directory>
<DirectoryRef Id="MBSAMPLECOLLECTIONS">
<Component Id="SampleCollections" Guid="C481566D-4CA8-4b10-B08D-EF29ACDC10B5" DiskId="1">
<File Id="movies.txt" Name="movies.txt" Source="SampleCollections\movies.txt" Checksum="no" />
<File Id="series.txt" Name="series.txt" Source="SampleCollections\series.txt" Checksum="no" />
<File Id="dummy.avi" Name="dummy.avi" Source="SampleCollections\dummy.avi" Checksum="no" />
</Component>
</DirectoryRef>
What's wrong with these Custom Actions or is there a simpler way to do this?
The obvious problems are that the way these custom actions are sequenced they won't properly support managed (elevated/UAC) instals or have any concept of servicing by MSI from a repair, rollback, uninstall, upgrade perspective.
It's hard to give exact advice without knowing exactly what you are doing. I know recently I had a customer who had an SDK with some "samples" that he wanted to instal per-user. I convinced this customer to just distribute ZIP files and write a simple winforms app that could handle asking the user a few questions and extracting these files to a directory of the users choice. This way they could deploy multiple instances of the samples, play with them, delete them, whatever without stepping on MSI's toes.