I'm trying to use RemoveFolderEx to delete a folder one level up from my install folder upon uninstall of the app. Here is what I have, but it's not working:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MyAppBaseFolder" Name="MyAppID">
<Directory Id="INSTALLFOLDER" Name="MyAppLauncher">
<Directory Id="UPDATESCRIPTSFOLDER" Name="Scripts" />
<Component Id="CleanupMainApplicationFolder" Guid="*">
<RegistryValue Root="HKLM" Key="SOFTWARE\MyApp ID\MyApp ID Windows Client" Name="Path" Type="string" Value="${path::getfullpath(path::combine([INSTALLFOLDER],'..\MyApp'))}" KeyPath="yes" />
<util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />
</Component>
</Directory>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="MyApp ID"/>
</Directory>
</Directory>
</Fragment>
The MSI will build fine, but when I run the setup it seems to be failing on the RegistryValue element and complaining about the ".." in the path. The string I'm making is like: "C:\Program Files (X86)\MyApp ID\MyAppLauncher\..\MyApp". I need it to resolve to: "C:\Program Files (X86)\MyApp ID\MyApp".
I'm not too familiar with the ${path:: ... } stuff. I saw a couple examples with ${path::combine()} so I guess I assumed that would work with getfullpath in .NET. Perhaps it does and my syntax is just wrong?
Thank you!
EDIT: Sorry, I got that ${path::combine... stuff from BUILDING WIX without fully reading what that article is doing. It has nothing to do with a wxs file, it's for NAnt (as Rob mentioned below). So I guess my question simply is this: how can I combine and resolve an absolute and relative path like C:\Program files (X86)\MyApp ID\MyAppLauncher\..\MyApp. Thanks
EDIT2: Thanks again Rob, I was focusing so much on resolving the path I didn't even consider the most obvious solution, which was to simply reference a new <Directory element. I now have it cleaning up 2 folders with the following code:
<Property Id="APPLICATIONFOLDER">
<RegistrySearch Key="SOFTWARE\MyApp ID\MyApp ID Windows Client" Root="HKLM" Type="raw" Id="APPLICATIONFOLDER_REGSEARCH" Name="Path" />
</Property>
<Property Id="PRINTERFOLDER">
<RegistrySearch Key="SOFTWARE\MyApp ID\MyApp ID Printer" Root="HKLM" Type="raw" Id="PRINTERFOLDER_REGSEARCH" Name="Path" />
</Property>
...
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MyAppBaseFolder" Name="MyAppID">
<Directory Id="INSTALLFOLDER" Name="MyAppLauncher">
<Directory Id="UPDATESCRIPTSFOLDER" Name="Scripts" />
<Component Id="CleanupMainApplicationFolder" Guid="*">
<RegistryValue Root="HKLM" Key="SOFTWARE\MyApp ID\MyApp ID Windows Client" Name="Path" Type="string" Value="[LM_INSTALLFOLDER]" KeyPath="yes" />
<util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />
<RegistryValue Root="HKLM" Key="SOFTWARE\MyApp ID\MyApp ID Printer" Name="Path" Type="string" Value="[LMP_INSTALLFOLDER]" />
<util:RemoveFolderEx On="uninstall" Property="PRINTERFOLDER" />
</Component>
</Directory>
<Directory Id="LM_INSTALLFOLDER" Name="MyApp" >
</Directory>
<Directory Id="LMP_INSTALLFOLDER" Name="MyAppPrinter" >
</Directory>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="MyApp ID"/>
</Directory>
</Directory>
</Fragment>
The syntax you have in the RegistryValue/#Value looks like NAnt or something. It isn't clear what interprets that but the Windows Installer will not. You have a couple options to get that registry value correct. First, change the RegistryValue element to look like:
<RegistryValue Root="HKLM"
Key="SOFTWARE\MyApp ID\MyApp ID Windows Client"
Name="Path"
Type="string"
Value="[MyAppBaseFolder]MyApp"
KeyPath="yes" />
Alternatively, you could define "MyApp" in your Directory tree and reference it directly. That'd look a little like adding the following as a child of MyAppBaseFolder (peer of INSTALLFOLDER):
<Directory Id='MyAppFolder' Name='MyApp' />
Then updating your RegistryValue element to look like:
<RegistryValue Root="HKLM"
Key="SOFTWARE\MyApp ID\MyApp ID Windows Client"
Name="Path"
Type="string"
Value="[MyAppFolder]"
KeyPath="yes" />
I prefer the latter but that's just because I prefer using identifiers without concatenating strings.
Related
I want to do the following where XLSTART is defined as:
<CustomAction Id="AssignXLSTART" Return="check" Execute="firstSequence" Directory ='XLSTART' Value='[AppDataFolder]\Microsoft\Excel\XLSTART'>
</CustomAction>
And then I have a subsequent CustomAction that calls some C# code that may change this value.
And then in the list of files to install I have:
<Directory Id="XlStartFolderId" Name="[XLSTART]">
<Component Id="ExcelMacro_xla" Guid="26D21093-B617-4fb8-A5E7-016493D46055" DiskId="1">
<File Id="ExcelXLA" Name="AutoTagExcelMacro.xlam" ShortName="XLMacro.xla" Source="$(var.srcFolder)\AutoTagExcelMacro.xlam"/>
</Component>
</Directory>
But the above puts it in the INSTALLDIR[XLSTART]. How do I get it to read this as a property?
You should be able to install to the userprofile directory you refer to like this:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="LocalAppDataFolder">
<Directory Id="Microsoft" Name="Microsoft">
<Directory Id="Excel" Name="Excel">
<Directory Id="XLSTART" Name="XLSTART">
<Component Id="ExcelAddIn" Feature="MyFeature" Guid="{11111-1111-GUID-HERE-YOURGUIDHERE}">
<File Source="C:\SourceFiles\MyAddin.xla" />
<RemoveFolder Id="Microsoft" On="uninstall" Directory="Microsoft" />
<RemoveFolder Id="Excel" On="uninstall" Directory="Excel" />
<RemoveFolder Id="XLSTART" On="uninstall" Directory="XLSTART" />
<RegistryValue Root="HKCU" Key="Software\MySoftware" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
I would suggest you use the per-machine xlstart folder instead - if it still exists. I am not sure it does. The the addin is loaded for every user on the box on every launch. Generally I prefer this. It has been ages since I looked at this, so this could have changed in newer Office versions - in fact I am sure it has, but the details are unclear to me.
System Folder Properties: There are a number of System Folder Properties that can be used in MSI files to specify installation location - LocalAppDataFolder is just one of them: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference#system-folder-properties
Figured it out. You need to install to the INSTALLDIR and then use CopyFile
<!-- place it in C:\Program Files (x86)\Microsoft Office\Root\Office16\XLSTART\ -->
<Component Id="ExcelMacro_xla" Guid="26D21093-B617-4fb8-A5E7-016493D46055" DiskId="1">
<File Id="ExcelXLA" Name="AutoTagExcelMacro.xlam" ShortName="XLMacro.xla" Source="$(var.srcFolder)\AutoTagExcelMacro.xlam">
<CopyFile Id='CopyXlMacro' DestinationProperty='XLPATH' DestinationName='AutoTagExcelMacro.xlam'/>
</File>
</Component>
I'm trying to add multiple shortcuts under a certain folder using Wix. The code looks like this:
<DirectoryRef Id ="TARGETDIR">
<Directory Id="DesktopFolder" Name="DesktopFolder">
<Component Id="DesktopP" Guid="61AE5ABE-9ED2-43B0-98C4-3050A40BF061">
<Shortcut Id="DesktopMyProgramShortcut" Name="$(var.MyProgramLabelShortcut)" Target="[#MyProgramcsproja015777b77a239eeb0bd49c2dafdbe31]" WorkingDirectory="bin"/>
<RemoveFolder Id="DesktopFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key="SOFTWARE\Example\Shortcuts" Name="167CE804-4A37-45B8-B010-EB6B3E73BE54" Type="string" Value="" KeyPath="yes"/>
</Component>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id ="ProgramMenuFolderMyProgram" Name ="$(var.MyProgramLabelShortcut)">
<Component Id="ProgramMenuMyProgram" Guid="A7B4A27B-9367-4AFF-B8CC-D6651B18FBFD">
<Shortcut Id="ProgramMenuMyProgramShortcut" Name="$(var.MyProgramLabelShortcut)" Target="[#MyProgramcsproja015777b77a239eeb0bd49c2dafdbe31]" WorkingDirectory="bin"/>
<Shortcut Id="ProgramMenuMyProgramManual" Name="$(var.MyProgramLabelShortcut)" Target="[documents]" Icon="shell32.dll" IconIndex="45"/>
<RemoveFolder Id="ProgramMenuFolderMyProgram" On="uninstall"/>
<RegistryValue Root="HKCU" Key="SOFTWARE\Example\Shortcuts" Name="167CE804-4A37-45B8-B010-EB6B3E73BE54" Type="string" Value="" KeyPath="yes"/>
</Component>
</Directory>
</Directory>
</DirectoryRef>
The weird behavior is that, when I try to place more than one shortcut, only the second one is added. I've tried placing the Shortcut in separate Components but still acts that way. In Windows7 works perfectly by the way.
Any suggestion about how to fix it?
Thanks in advance!
The problem had to do with the name of the shortcuts. I guess that, since their names were equal, the first shortcut was overwritten by the second one. I've fixed it changing the name of the second shortcut.
I have created a multi lingual app that uses 2 diferent resource files to manage the UI language, so when I build and execute my program, in my bin directory I have my app files and two folders, en-GB and pt-PT.
I am now trying to create a installer with Wix, for that I am defining the following directories:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="App" >
<Directory Id="LOCALEEN" Name="en-GB"/>
<Directory Id="LOCALEPT" Name="pt-PT"/>
</Directory>
</Directory>
</Directory>
</Fragment>
And then, I define the following components:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="App.resources.en.GB.dll" Guid="...">
<CreateFolder />
<File Id="App.resources.en.GB.dll" Name="App.resources.dll" Source="$(var.App.App_TargetDir)en-GB\App.resources.dll" />
</Component>
<Component Id="App.resources.pt.PT.dll" Guid="...">
<CreateFolder />
<File Id="App.resources.pt.PT.dll" Name="App.resources.dll" Source="$(var.App.App_TargetDir)pt-PT\App.resources.dll" />
</Component>
... Other components...
</ComponentGroup>
</Fragment>
When I rebuild my solution I get the following error:
'App.resources.dll' is installed in '[ProgramFilesFolder]\App\' by two
different components on an LFN system: 'App.resources.en.GB.dll' and
'App.resources.pt.PT.dll'. This breaks component reference counting.
I understand the problem, both resources dll are being copied to the installation folder, and not to the specific resources file... But I don't know how to solve it. Anyone can give any hints on how to solve this?
Just reference the directory where you want your components eg. Directory="LOCALEEN". There is no need to specify <CreateFolder />
I also recomend to maintain some kind of naming convention. Your Components and Fils have the same id. See https://stackoverflow.com/a/1801464/4634044. So this should do what you expect:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="C_EnglishLocale" Guid="..." Directory="LOCALEEN">
<File Id="Fi_EnglishLocale" Name="App.resources.dll" Source="$(var.App.App_TargetDir)en-GB\App.resources.dll" />
</Component>
<Component Id="C_PolnishLocale" Guid="..." Directory="LOCALEPT">
<File Id="Fi_PolnishLocale" Name="App.resources.dll" Source="$(var.App.App_TargetDir)pt-PT\App.resources.dll" />
</Component>
</ComponentGroup>
</Fragment>
In my wix source code, I have to look for 2 entries in the registry to get an install directory :
<Property Id="INSTALLDIR_A">
<RegistrySearch Id='RegA' Type='raw'
Root='HKLM' Key='Software\Path\To\A' Name='InstallLocation' />
<Property Id="INSTALLDIR_B">
<RegistrySearch Id='RegB' Type='raw'
Root='HKLM' Key='Software\Path\To\B' Name='InstallLocation' />
My install directory must be either INSTALLDIR_A or INSTALLDIR_B. If I had to look only to 1 entry, I would have implemented it like that :
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" Name="My path">
<!-- further code -->
</Directory>
</Directory>
But I want INSTALLDIR to be either INSTALLDIR_A or INSTALLDIR_B depending on which one is defined. How to achieve this ?
There's a custom action SetDirectory (http://wixtoolset.org/documentation/manual/v3/xsd/wix/setdirectory.html) for that. You might try something like using the first value as default and overwriting it if the other one is set:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Software\Path\To\A" />
</Directory>
</Directory>
<SetDirectory Id="INSTALLFOLDER" Value="[INSTALLDIR_B]">INSTALLDIR_B AND NOT INSTALLDIR_A</SetDirectory>
</Fragment>
I am trying to remove a folder on "install" (and "uninstall"), but the folder is only removed on "uninstall".
Any hints how this can be done?
<Property Id="PACKAGEFOLDER">
<RegistrySearch Root="HKLM" Key="$(var.RegKey)" Type="raw" Id="PKGFOLDER_REGSEARCH" Name="PkgDir" />
</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="PACKAGE" Name="$(var.PkgFolder)">
<Component Id="PackagesFiles" Guid="$(var.FilesGUID)">
<RegistryValue Root="HKLM" Key="$(var.RegKey)" Name="PkgDir" Type="string" Value="[PACKAGE]" KeyPath="yes" />
<util:RemoveFolderEx On="both" Property="PACKAGEFOLDER" />
</Component>
</Directory>
</Directory>
</Directory>
just noticed:
if the RegKey is available in registry before installation starts, it will work:
WixRemoveFoldersEx: Recursing path: C:\Program Files (x86)... for
row: wrf945C37509CA5EEDC2367957D5F072DFF. MSI (s) (94!A8)
[19:17:55:185]: PROPERTY CHANGE: Adding _UNOPACKAGEFOLDER_0 property.
Its value is 'C:\Program Files (x86)... MSI (s) (94:D4)
[19:17:55:185]: Doing action: CostInitialize
but if the RegKey is not in registry, log says:
WixRemoveFoldersEx: Error 0x80070057: Missing folder property:
APPLICATIONFOLDER for row: wrfA308D08284221970F6338358BFB75917
CustomAction WixRemoveFoldersEx returned actual error code 1603 but
will be translated to success due to continue marking MSI (s) (84:50)
[19:29:08:529]: Doing action: CostInitialize
Is it possible to write the RegKey before the Property "PACKAGEFOLDER" is set?
I assume that you have also files in this folder that should be deleted. If there are no (arbitrary) subdirectories containing files it should be straight forward by using the RemoveFile-table of the Windows Installer. As it will only delete the folder if it is empty, add an additional entry that will delete the files in it, e.g.:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="PACKAGE" Name="$(var.PkgFolder)">
<Component Id="PackagesFiles" Guid="$(var.FilesGUID)">
<RegistryValue Root="HKLM" Key="$(var.RegKey)" Name="PkgDir" Type="string" Value="[PACKAGE]" KeyPath="yes" />
<RemoveFile Id="RemovePACKAGEFolderFiles" Directory="PACKAGE" Name="*.*" On="both" />
<RemoveFolder Id="RemovePACKAGEFolder" Directory="PACKAGE" On="both" />
</Component>
</Directory>
</Directory>
</Directory>
This way you don't have to deal with any property setting. If you have other subdirectories with files you would have to repeat this also for these.
Another way would be to create a deferred custom action in the system context that will delete the folder completely, e.g. in VBScript.
If you add
<SetProperty Id="PACKAGEFOLDER" Value="[PACKAGE]" After="CostFinalize" />, you can get the value of package during install. From this article regarding property-setting.