How to write a registry key and value in bundle of wix? - wix

I can write a registry key and value in setup project of wix,the code like this:
<RegistryKey Id="WinApp" Root="HKLM" Key="Software\App\[ProductName]" Action="createAndRemoveOnUninstall" >
<RegistryValue Type="string" Name="InstallName" Value="[ProductName]" Action="write" KeyPath="yes"></RegistryValue>
</RegistryKey>
How can i do in bootstrapper project?

Bundles do not modify the machine state. The registry key should be placed in one of the chained packages to be part of the installation transaction.

Related

Wix install location

I have a WIX setup that allows the user to select the install location. When uninstalling, I need to run a custom action that should activate a file in the install location. I tried getting the install location from session["INSTALLDIR"] but it results in the default path and not the one given by the user.
How can I reach that location?
I've done this in my own installer - the following should work.
This adds a property to retrieve the install location value from the registry.
<Property Id="INSTALLDIR">
<RegistrySearch Id='Registry' Type='raw' Root='HKCU' Key='Software\$(var.Manufacturer)\$(var.ProductName)' Name='Location' />
</Property>
This sets the install location in the registry.
<Component Id="Registry" Guid="*">
<RegistryKey Root="HKCU" Key="Software\$(var.Manufacturer)\$(var.ProductName)">
<RegistryValue Name="Location"
Type="string"
Value="[INSTALLDIR]"
Action="write"
KeyPath="yes" />
</RegistryKey>
<util:RemoveFolderEx On="uninstall" Property="INSTALLDIR" />
If you want INSTALLDIR for a later time such as uninstallation you should use Remember property pattern described in link below.
"The root issue is that the Windows Installer does not save Property values for you. That means if the user enters values in the install UI or passes them on the command-line, those values will be not be present during repair, upgrade nor uninstall."
http://robmensching.com/blog/posts/2010/5/2/the-wix-toolsets-remember-property-pattern/

Wix registry key changing

I'm using a WiX installer file to edit a registry entry however when it's uninstalled I want it to be set do a default value of 0.
Here is the code I'm using to set it to 1.
<DirectoryRef Id="TARGETDIR">
<Component Id="RegistryEntries" Guid="PUT-GUID-HERE">
<RegistryKey Root="HKCU"
Key="Software\Microsoft\Windows\CurrentVersion\Policies\System"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="integer" Name="DisableTaskMgr" Value="1" KeyPath="yes"/>
</RegistryKey>
</Component>
I want it so that when it uninstalls that it does not delete the key but just sets it to 0 as I am unsure what the behaviour of the taskmanager would be if the key was deleted.
I'm also assuming Action="createAndRemoveOnUninstall" should be something else?
"Action" has been deprecated and instead you should be using "ForceCreateOnInstall" and/or "ForceDeleteOnUninstall" instead.
You can also use "NeverOverwrite" on the component to make sure that the registry value isn't removed.
To set the value you can use a custom action that is scheduled to run only during the uninstall. Use NOT UPGRADINGPRODUCTCODE as the conditional for your custom action to ensure it only executes during uninstall.
For the custom action under Product AND Package add
<InstallExecuteSequence>
<Custom Action="YourCustomAction" After="InstallInitialize"><![CDATA[(NOT UPGRADINGPRODUCTCODE)]]></Custom>
</InstallExecuteSequence>

Using WiX, how to skip a component when a certain registry key does not exist?

I want to copy some files into a directory in another product's installation tree, but only if that product is installed. So I figured I could set a property based on a registry search to find that product's installation root. Then I could use the property in a condition element on the component element.
Here is my code. For some reason, I am getting an error when the other product is not installed and the registry search comes up empty since the registry key will not be found.
<Property Id="PRODUCTPATH">
<RegistrySearch Id="PRODUCTPATH" Root="HKLM" Key="_MY_KEY_" Name="_MY_NAME_" Type="raw" />
</Property>
<SetProperty Id="PRODUCTBINPATH" Value="[PRODUCTPATH]\BIN" After="AppSearch"/>
<Component Id="CommonDLLs" Guid="_MY_GUID_" Directory="INSTALLLOCATION">
<Condition>PRODUCTPATH</Condition>
<RegistryValue Id="_MY_ID_" Root="HKLM" Key="_MY_KEY_2" Name="Installed" Value="1" Type="integer" KeyPath="yes" />
<CopyFile Id="myfile1.dll" FileId="myfile1.dll" DestinationProperty="PRODUCTPATH" DestinationName="myfile1.dll"/>
<CopyFile Id="myfile2.dll" FileId="myfile2.dll" DestinationProperty="PRODUCTPATH" DestinationName="myfile2.dll"/>
</Component>
Try to use the util:RegistrySearch instead of RegistrySeach
This element comes with Util Extension. Check here if you don't know how to use extensions.
The util:RegistrySearch has an attribute (Result) for only checking if the key exists or not.
It would be like that:
<util:RegistrySearch
Id="PRODUCTPATH"
Variable="PRODUCTPATH"
Root="HKLM"
Key="_MY_KEY_"
Format="raw"
Result="exists">
Actually, all you have to do is add a condition to the SetProperty element like this:
<Property Id="PRODUCTPATH">
<SetProperty Id="PRODUCTBINPATH" Value="[PRODUCTPATH]\BIN" After="AppSearch">PRODUCTPATH</SetProperty>

Wix registry editing not displayed in the msi log

I've been working on a WIX .net project that needs to update a Microsoft registry entry to work correctly. While testing the logic, I found it difficult to debug the WIX components that updates the registry via the MSiexec.exe command line /log options. To verify the correct behaviour, I had to check the registry value manually. How do I force the WIX project to log the registry search and update logic from the following fragment in the MSI log output?
<util:RegistrySearch Id="Office2013RegistySearch"
Root="HKLM"
Key="SOFTWARE\Microsoft\Office\15.0\Access Connectivity Engine\Engines\Excel"
Value="TypeGuessRows"
Variable="Office2013GuessRowsx86Exist"
Win64="no"
Result="exists" />
<Component Id="Office2013GuessRowsx86RegComponent" Guid="CFE579F9-292A-4777-A671-B5E8E330B1A0" Win64="no">
<Condition>Office2013GuessRowsx86Exists</Condition>
<RegistryKey Root="HKLM"
Key="SOFTWARE\Microsoft\Office\15.0\Access Connectivity Engine\Engines\Excel" ForceDeleteOnUninstall="no">
<RegistryValue Type="integer" Name="TypeGuessRows" Value="0"/>
</RegistryKey>
</Component>
Try use full log
msiexec /i "dotnetproject.msi" /L*v "log.log"
or add <Property Id="MsiLogging" Value="voicewarmup"/> (for full log too)

Associate file type to external program in WiX

Is there a way to associate a file extension to an external program in my WiX setup?
For example, my application uses .xyz files, but I use a third party program to edit them, like Notepad++. I would include Notepad++ during the setup or bootstrap its installer. Is there a way to associate Notepad++ with my .xyz files using only WiX?
I've looked at the ProgId element, but I don't think it can do this.
Unfortunately, the strongly typed elements cannot be used to refer to an executable outside of the install today. However, you can write the registry keys yourself. Something like:
<RegistryValue Root="HKCR" Key=".xyz" Value="xyz-progid" Type="string" />
<RegistryKey Root="HCKR" Key="xyz-progid>
<RegistryValue Key="shell\Open\command" Value="[NOTEPADPLUSPLUSPATH]" Type="string" />
<RegistryValue Key="DefaultIcon" Value="[!NOTEPADPLUSPLUSPATH]" Type="string" />
</RegistryKey>
For this to work, you'll need to find Notepad++ on the machine. I'm not sure how to do that but let's say there was a registry key that told you:
<Property Id="NOTEPADPLUSPLUSPATH">
<RegistrySearch Id="FindNotepadPlusPlus" Root="HKLM" Key="Software\NotepadPlusPlus"
Name="InstallPath" Type="raw" />
</Property>