Wix registry key changing - wix

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>

Related

Wix tools Ignore registry fail and continue

I need to insert a registry key in wix but the result is not important
how can I Ignore error.
sometimes because of permission reg creation fails
<Component Id="EXTEND_ADVANCE_TEXT_SERVICE" Guid="*">
<RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\CTF\SystemShared" Action="createAndRemoveOnUninstall">
<RegistryValue Type="integer" Name="CUAS" Value="1" KeyPath="yes"/>
</RegistryKey>
<Condition><![CDATA[VersionNT >= 501 AND VersionNT <= 502]]></Condition>
</Component>
The RegistryKey element does not have any error handling. Use a custom action and ignore the return code. There are plenty ways to do this, you can either author one in code or use a quiet execution custom action.

Wix set program run as admistrator

I have already set the program run as the windows startup, however the program can only work when it is run as administrator in windows 10, can anybody tell me what I should add in the code to set that? Here is my Wix code:
In product modules there is
<ComponentRef Id="RegistryEntries"/>
and then
<Fragment>
<DirectoryRef Id="ProgramFilesFolder">
<Component Id="RegistryEntries" Guid="14fe9526-0da4-4761-ad27-8a77f145c6b5">
<RegistryKey Root="HKCU"
Key="Software\Microsoft\Windows\CurrentVersion\Run"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="March Networks Video Assistant" Value="[INSTALLFOLDER]March Networks Video Assistant.exe" KeyPath="yes"/>
</RegistryKey>
</Component>
</DirectoryRef>
</Fragment>
Thank you so much to everybody.
The problem is you are putting this registry key in the HKCU which will run things in the current user's context at startup.
If you want it to be run as administrator on startup it needs to go into HKLM.
Try the following:
<Fragment>
<DirectoryRef Id="ProgramFilesFolder">
<Component Id="RegistryEntries" Guid="14fe9526-0da4-4761-ad27-8a77f145c6b5">
<RegistryKey Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Run"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="March Networks Video Assistant" Value=""[INSTALLFOLDER]March Networks Video Assistant.exe"" KeyPath="yes"/>
</RegistryKey>
</Component>
</DirectoryRef>
</Fragment>
So notice I changed HKCU to HKLM (this might cause ICE warnings during compilation but you can safely ignore them). If you are using a per user install, I don't know if this will be able to write the registry key though unless the install is run as administrator... Also I put " around your RegistryValue's value since it's always nice to wrap full paths in quotes because of spaces.
Another nice thing you can do is update the RegistryValue's value using the install path of the component which can be referenced using the following syntax:
[#IDOfFile]
So if your component defining the "March Networks Video Assistant.exe" <File> uses Id="MarchNetworksVideoAssistant.exe" you can update your RegistryValue's value to
value=""[#MarchNetworksVideoAssistant.exe]""
You can get a good explanation of this syntax here
If a substring of the form [#filekey] is found, it is replaced by the full path of the file, with the value filekey used as a key into the File table. The value of [#filekey] remains blank and is not replaced by a path until the installer runs the CostInitialize action, FileCost action, and CostFinalize action. The value of [#filekey] depends upon the installation state of the component to which the file belongs. If the component is run from the source, the value is the path to the source location of the file. If the component is run locally, the value is the path to the target location of the file after installation. If the component has an action state of absent, the installed state of the component is used to determine the [#filekey] value. If the installed state of the component is also absent or null, [#filekey] resolves to an empty string, otherwise it resolves to the value based upon the component's installed state. For more information about checking the installation state of components, see Checking the Installation of Features, Components, Files.

How can I remove a RegistryValue on uninstall without removing the parent RegistryKey with WIX?

If I use the follow code then nothing is removed on uninstall.
<DirectoryRef Id="INSTALLDIR">
<Component Guid="xyz" Id="instance_path" MultiInstance="yes">
<RegistryKey ForceCreateOnInstall="yes" Id="instance_path_reg" Key="Software\i-net software GmbH\i-net Test\Instances" Root="HKLM">
<RegistryValue Name="[INSTANCE_NUMBER]" Type="string" Value="[INSTALLDIR]"/>
</RegistryKey>
</Component>
</DirectoryRef>
If I replace ForceCreateOnInstall="yes" with ForceDeleteOnUninstall="yes" then all is removed on uninstall.
But I want only remove the RegistryValue of this instance. The values of other instances should not removed.
You could try using the RemoveRegistryValue and leave your current entries. It is a little messy but should get the job done.
http://wixtoolset.org/documentation/manual/v3/xsd/wix/removeregistryvalue.html
The problem was that the property INSTANCE_NUMBER was not set on uninstall. The uninstaller has try to delete a not existing key.

Wix - Get user input to create a registry entry

I need to create an installer that gets the user input to create a registry entry. I've looked into Wix tutorials and it's very clear how to install registry entries but I need the user to give some info(in this case it's an url) so that url can be used on the registry entry.
How can I do this?
Duplicate question!?
Please take a look at this answer if it helps: https://stackoverflow.com/a/20679626/1331719
Edit - slightly modifying the answer found in the link:
Start by adding this component, notice the property in Value [USERINPUT]
<DirectoryRef Id="INSTALLDIR">
<Component Id="RegistryEntries" Guid="{YOURGUID}">
<RegistryKey Root="HKLM" Key="Software\Company123\App123" Action="create">
<RegistryValue Type="string" Name="UserInput" Value="[USERINPUT]" />
</RegistryKey>
</Component>
</DirectoryRef>
Reference the component in your feature:
<Feature>
<ComponentRef Id="RegistryEntries" />
...
</Feature>
Get user input when you install using msiexec:
msiexec /i your.msi /qb+ USERINPUT="http://urlYouWantToStoreIn.Registry"
Check registry HKLM\Software\Company123\App123\UserInput, the url should be there.

How to write a registry key and value in bundle of 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.