I am having problems setting the TARGETDIR path. I used dark.exe to reverse engineer a working MSI file and read any posts I could find on this subject, but I seem to be unable to set the TARGETDIR to point to the path ProgramFiles\Manufacturer\Product. Below is a distilation of my WXS file which results in my application being installed to the root of my D-drive for some reason:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*"
Name="FBL - Some App"
Language="1033"
Version="1.0.0.0"
Manufacturer="Foo & Bar Limited"
UpgradeCode="780286c6-e064-4402-80d8-dd2c68b56c04">
<Package InstallerVersion="200"
Compressed="yes"
InstallScope="perMachine"
Comments="Performs some operation that is important" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="App.1.0.0.cab" EmbedCab="yes" />
<CustomAction Id="setTARGETDIR"
Property="TARGETDIR"
Value="[ProgramFilesFolder][Manufacturer]\[ProductName]"
Execute="firstSequence"
Return="check" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="C__App.exe"
Guid="{074586E9-A675-2734-A4CD-1CE520922A41}">
<File Id="F__App.exe"
Name="App.exe"
KeyPath="yes"
Assembly=".net"
AssemblyManifest="F__App.exe"
AssemblyApplication="F__App.exe"
DiskId="1"
Source="D:\SomePath\bin\Debug\App.exe" />
</Component>
</Directory>
<Feature Id="DefaultFeature" ConfigurableDirectory="TARGETDIR" Level="1">
<ComponentRef Id="C__App.exe" Primary="yes" />
</Feature>
<Icon Id="favicon.ico" SourceFile="d:\SomePath\favicon.ico" />
<Property Id="ARPPRODUCTICON" Value="favicon.ico" />
<UI />
<InstallExecuteSequence>
<Custom Action="setTARGETDIR" Before="CostFinalize" />
</InstallExecuteSequence>
</Product>
</Wix>
I'm sure I am missing something simple, but I cannot find any further information on what to do from here.
The following modifications were needed:
<CustomAction Id="SetTARGETDIR"
Directory="TARGETDIR"
Value="[ProgramFilesFolder][Manufacturer]\[ProductName]"
Return="check" />
and
<InstallExecuteSequence>
<Custom Action="SetTARGETDIR" After="InstallValidate" />
</InstallExecuteSequence>
Explanation: Use the Directory attribute instead of a property (it's a type 35 custom action) and schedule this action after InstallValidate in the execute sequence - that's when directories are checked for write access and truly set.
(Thanks to Narina Chandra Sekhar, from the WiX user group for the answer on this.)
This is strange...I had the same issue but your answer didn't work for me. All I needed was this:
<Product>
<SetProperty Id='TARGETDIR' Value='[ProgramFilesFolder][Manufacturer]\[ProductName]\' Before='FindRelatedProducts' />
...
</Product>
But then again I think something else in my installer may have been setting the TARGETDIR directory from the property; I was working with some legacy stuff.
Edit: Actually, that was a bad idea. A lot of times, some of these custom actions that are built in can be called at different parts of the installation process, so its just better to add a custom action to set the property.
Here is what worked for me:
<Product>
<CustomAction Id='SetTARGETDIR' Property='TARGETDIR' Value='[ProgramFilesFolder][Manufacturer]\[ProductName]\'/>
...
</Product>
<InstallUISequence>
<Custom Action='SetTARGETDIR' Sequence='1'/>
...
</InstallUISequence>
<AdminUISequence>
<Custom Action='SetTARGETDIR' Sequence='1'/>
...
</AdminUISequence>
Nothing worked for me so what I did is to run the msi with a command line setting the property of the installation directory. By default my program would be installed to drive C but sometimes I wanted it to be installed to D drive so here is what I did:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="XServer">
</Directory>
</Directory>
</Directory>
Here is the command line:
XServer.msi /L*v log.log APPLICATIONROOTDIRECTORY="D:\Program Files (x86)\XServer"
This actually worked for me. The CostFinalize action is where TARGETDIR Directory is defined.
<SetProperty Id="TARGETDIR" Value="[ROOTDRIVE]MyCompany" Sequence="first" Before="CostFinalize">NOT Installed AND NOT TARGETDIR</SetProperty>
I tried changing the installation dir via custom action (cause I needed code to figure out the path with code - long story), and what solved it for me what the timing - I had to schedule the custom action to:
After="CostInitialize"
Related
I created a simple WIX project with a "Hello world" custom action and checked how it works. I intended the custom action to be executed only on the first install, but it executed on every major update(where both the product code and its version change). I found in the log that the custom action condition is checked after uninstall - when the Installed variable is false again.
How do I execute a custom action on the first install only and not on major updates, using the WIX toolset?
Is there a way without manual use of the registry?
<Product Id="52D5F5ED0C3F453CA70E280ECD7D7400"
Name="TestWiXSetup"
Language="1033"
Version="1.0.2.0"
Manufacturer="Some RnD"
UpgradeCode="12777105-8bc1-47b5-8b36-2705ef02cb79">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab='yes' />
<Feature Id="ProductFeature" Title="TestWiXSetup" Level="1">
<ComponentRef Id="Component" />
</Feature>
<Binary Id="HW" SourceFile="HW.exe" />
<CustomAction Id="HWA" BinaryKey="HW" ExeCommand="" Execute='deferred'/>
<InstallExecuteSequence>
<Custom Action='HWA' After='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="TestWiXSetup">
<Component Id="Component">
<File Source="ToDeploy.txt"/>
</Component>
</Directory>
</Directory>
</Directory>
</Fragment>
I need to copy a DLL into the system32 folder, that's my WIX script but it doesn't work, the copy command just fails:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="LMBrick Service" Language="1033" Version="1.3.0.0"
Manufacturer="MyCompany" UpgradeCode="3de1a175-3701-435f-90bc-e97cb66b5524">
<Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated" AdminImage="yes" InstallScope="perMachine" Platform="x64" />
<Property Id="MSIUSEREALADMINDETECTION" Value="1" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="cab1.cab" EmbedCab="yes" />
<Feature Id="ProductFeature" Title="LMBrickServiceInstallation" Level="1">
<ComponentGroupRef Id="LMBrickComponents" />
</Feature>
<CustomAction Id="InstallLMBrickDll" Directory="LMBRICKINSTALLFOLDER" Execute="deferred" Impersonate="no"
ExeCommand="copy LMBrick.dll [System64Folder]LMBrick.dll"
Return="check" />
<InstallExecuteSequence>
<Custom Action="InstallLMBrickDll" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="Company" Name="MyCompany">
<Directory Id="App" Name="MyProduct">
<Directory Id="LMBRICKINSTALLFOLDER" Name="LMBrickService">
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>
</Wix>
Custom Actions that run Exes have to actually run an exe. However copy is not an exe; it's built into the command shell. So you have two immediate choices (and two better choices later):
Find an actual exe, such as xcopy.exe, and run that instead, or
Execute a shell such as cmd.exe with arguments that invoke its copy builtin.
You can confirm this by opening up a command prompt and executing the commands where copy and where xcopy respectively. Note that launching cmd.exe or any console program as an Exe will result in a console window flashing by during installation. This typically looks rather unprofessional, and you should use one of two alternatives:
Wrappers such as WixQuietExec can suppress the console window, or
Built-in Windows Installer functionality, such as exposed through CopyFile, can avoid the need for a custom action at all.
If possible, it's best to avoid custom actions and use Windows Installer functionality. So aim for the last option if you can.
I have a simple working EXE wrapper in WIX but I don't like that I have to add at least one file for it to work and I can't seem to find a way to not add files to it, is it even possible?
<?xml version="1.0" encoding="UTF-8" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product>
<Package Compressed="yes" InstallerVersion="301" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MyProgramDir" Name="MyInstaller">
<Single unwanted dummy component here>
</Directory </Directory>
</Directory>
<Binary Id="MYEXE" SourceFile="Installer.exe" />
<CustomAction Id="RunInstaller" BinaryKey="MYEXE" ExeCommand="" Impersonate="no" Execute="deferred" Return="asyncNoWait" />
<InstallExecuteSequence>
<Custom Action="RunInstaller" Before="InstallFinalize">
NOT Installed
</Custom>
</InstallExecuteSequence>
<Feature Id="ProductFeature" Level="1">
<Single unwanted dummy component ref here>
</Feature>
</Product>
</Wix>
You don't have to have atleast one file (although the scenarios where you don't have any files are very, very rare) you do have to have atleast 1 component and that component has to have a key. The key can be a file, registry entry or by default directory.
The old saying is that installers is more then just copying files but generally they always include atleast copying a file or two.
When I run my installer I get the following issue.
I'm doing some custom actions which require to access the registry and I can only think that its because the WiX configuration doesn't make it request admin priveleges. I've looked at some posts on SO and tried to use.
InstallPriveleges="elevated"
within the package element however this does not make the installer have the admin shield nor request it therefore still producing the error.
Extra information about test project.
The name of my application is :WindowsFormsApplication33, the name of the custom action project is CustomAction1 and name of the Setup project is SetupProject1.
This is my current wix xml file.
<Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated" InstallScope="perUser" />
<Binary Id="CustomAction1.CA.dll" SourceFile ="..\CustomAction1\bin\$(var.Configuration)\CustomAction1.CA.dll" />
<CustomAction Id="disableTaskManager"
Return="check"
Execute="immediate"
BinaryKey="CustomAction1.CA.dll"
DllEntry="disableTaskManager" />
<CustomAction Id="enableTaskManager"
Return="check"
Execute="immediate"
BinaryKey="CustomAction1.CA.dll"
DllEntry="enableTaskManager" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<InstallExecuteSequence>
<Custom Action="disableTaskManager" Before="InstallFinalize" />
<Custom Action="enableTaskManager" After="InstallInitialize"><![CDATA[(NOT UPGRADINGPRODUCTCODE)]]></Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Form Test Application" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Guid="{EDA315F6-A115-4348-8607-981C252EA317}">
<File Source="$(var.WindowsFormsApplication33.TargetPath)" KeyPath ="yes" />
</Component>
<Component Guid="{E3182F61-F563-4C13-82B5-8CC39D9DB380}">
<File Source="$(var.CustomAction1.TargetPath)" KeyPath ="yes" />
</Component>
<Component Guid="{E4AF325E-B244-47F5-855A-5B40DBC425D2}">
<File Source="..\WindowsFormsApplication33\bin\Release\WindowsFormsApplication33.exe.config" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
Update : changing the InstallScope value from perUser to "perMachine" does make a UAC prompt however the DLL error still exists..
Your custom action is immediate, that means it will not run with elevation. It must be deferred to run with elevation. It's got nothing to do with WiX particularly, it's just that immediate custom actions run as the user but limited.
I struggled to get rid of the dll error however an alternative I found was to NOT use Custom Action and use the XML in the wix file to create the registry and then delete the key when uninstalling via the use of :
ForceDeleteOnUninstall="yes"
You have to use this in the
Example :
<!-- Register windows autostart registry -->
<Component Id="RegistryEntries" Guid="45C7AC46-1101-4301-83E1-D24392283A60">
<RegistryValue Type="string"
Name="FooStartup"
Value="[#FooMainApp]"
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Run"
Action="write"/>
</Component>
As found on : Registry change upon installing application C#
I really hope this helps someone new to WiX as it did to me.
Use these three attributes inside custom action tag.
<CustomAction ....
Execute="deferred"
Impersonate="no"
Return="ignore" />
These fields will make the custom action to run with admin priveleges.
So I'm creating my first Wix project and I seem to be having a problem executing a custom action. I'm not sure that it's being included in the msi and I'm not quite sure what I'm doing wrong. The following is my Wix file:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="ExactaDynamicManifest" Language="1033" Version="1.0.0.0" Manufacturer="Bastian Software Solutions" UpgradeCode="274ff2d9-e291-4706-a8db-ce80ccd91538">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="ExactaDynamicManifest" Level="1">
<ComponentGroupRef Id="ExactaDynamicManifest"/>
</Feature>
<Icon Id="exacta.ico" SourceFile="icons\exacta.ico"/>
<Property Id="ARPPRODUCTICON" Value="exacta.ico" />
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ExactaFolder" Name ="Exacta">
<Directory Id="INSTALLFOLDER" Name="ExactaExactaDynamicManifest" />
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<CustomAction Id="InstallService" FileKey="ExactaDynamicManifest.exe" ExeCommand="install"/>
<InstallExecuteSequence>
<Custom Action="InstallService" After="InstallFinalize"/>
</InstallExecuteSequence>
</Fragment>
</Wix>
The last fragment contains my custom action which what I hoped would do is the following on the command line after all files have been placed in the directory:
ExactaDynamicManifest.exe install
One thing to note is that exe is actually coming from a ComponentGroupRef defined above. Not sure if this is a problem or not but thought I'd mention it. Any help would be appreciated.
I finally got something that is working. My initial problem of the CustomAction not loading seemed to be due to it being in a different <fragment>. I consolidated all of the code into a single fragment and it seemed to run.
After battling with user permissions etc I finally ended up with this solution:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="ExactaDynamicManifest" Language="1033" Version="1.0.0.0" Manufacturer="Bastian Software Solutions" UpgradeCode="274ff2d9-e291-4706-a8db-ce80ccd91538">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="ExactaDynamicManifest" Level="1">
<ComponentGroupRef Id="ExactaDynamicManifest"/>
</Feature>
<Icon Id="exacta.ico" SourceFile="icons\exacta.ico"/>
<Property Id="ARPPRODUCTICON" Value="exacta.ico" />
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ExactaFolder" Name ="Exacta">
<Directory Id="INSTALLFOLDER" Name="ExactaExactaDynamicManifest" />
</Directory>
</Directory>
</Directory>
<CustomAction Id="RunTopShelfServiceInstall" Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="no" ExeCommand="[INSTALLFOLDER]ExactaDynamicManifest.exe install"/>
<CustomAction Id="RunTopShelfServiceUninstall" Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="no" ExeCommand="[INSTALLFOLDER]ExactaDynamicManifest.exe uninstall"/>
<InstallExecuteSequence>
<Custom Action="RunTopShelfServiceInstall" After="InstallFiles">
NOT Installed
</Custom>
<Custom Action="RunTopShelfServiceUninstall" After='InstallInitialize'>
(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
</Custom>
</InstallExecuteSequence>
</Fragment>
</Wix>
Are you going to register a service using a custom action?
You also have to handle uninstall, repair actions.
It's much simpler to use standard MSI feature to install services:
http://wixtoolset.org/documentation/manual/v3/xsd/wix/serviceinstall.html
If you want to use custom actions for this purpose and UAC is enabled your service won't be installed due to permissions.
You have to use deferred and not impersonated custom action scheduled before InstallFinalize (after InstallFinalize custom actions can't be scheduled).