How to write Product Id in registry in wix - wix

My requirement is blow.
I need to write the Product Id in registry while install the setup.
I have the below code for Product Id.
<Product Id="{CEEE7807-F6D7-43F6-A206-110B9E25AC9C}"
Name="Sample installer"
UpgradeCode="{BFBD4770-8C5D-4A53-BA07-EF52401F0CB4}"
Language="1033"
Version="$(var.ProductVersion)"
Manufacturer="My company.">
I have below code for write Registry. I want to pass the product Id value here.
<Component Id="registry_values" Guid="{11FB6C4C-3C90-4F46-B0D2-BB95150F60E6}">
<RegistryValue
KeyPath="yes"
Root="HKCU"
Key="Software\MyProduct\Myfolder\SampleFolder\Product"
Value="[Product Id]"
Type="string" />
</Component>
Please help me to solve this problem.

Somewhat confusingly, the Id attribute of the WIX Product element maps to the Windows Installer ProductCode property.
<Component Id="registry_values" Guid="{11FB6C4C-3C90-4F46-B0D2-BB95150F60E6}">
<RegistryValue
KeyPath="yes"
Root="HKCU"
Key="Software\MyProduct\Myfolder\SampleFolder\Product"
Value="[ProductCode]"
Type="string" />
</Component>

Related

Bind FileVersion to property in WiX

As for binding the AssemblyVersion of a specific DLL to WiX File Version, is basically easy:
<Product Id="*"
Name="My Application"
Language="1033"
Version="!(bind.FileVersion.MyDll.dll)"
Manufacturer="My Company"
UpgradeCode="E7A0C56F-160B-4C67-9AAC-2FF69630EAF9">
Is there any way that the same can be achieved with Properties in WiX. Like this:
<Property Id="VERSION">
<![CDATA[!(bind.FileVersion.MyDll.dll)]]>
</Property>
I need to update an XML file during installation, with the same version number as the one in the specific DLL. Any suggestions?
You should have a look at the XmlFile Element. It allows you to set values/attributes:
<Component Id="webconfig" Guid="PUT-YOUR-GUID-HERE" NeverOverwrite="yes" Win64="yes">
<File Id="web.config" Source="$(var.bind.ProjectDir)\web.config" KeyPath="yes" />
<util:XmlFile Id="web.config.VersionInfo" File="[#web.config]" Action="setValue" PreserveModifiedDate="yes" ElementPath="//configuration/appSettings/add[\[]#key='VersionInfo'[\]]" Name="value" Value="[VERSION]" Sequence="1" />
</Component>

Wix shortcut desktop - is this code for current user or all users

I am trying to create a shortcut for all users using Wix 3.6. My InstallScope is perMachine and InstallPriviledges is elevated. I build this code ok. It runs ok. Does this produce a shortcut for all users or just the current user and what do I need to change to make a shortcut for all users?
<DirectoryRef Id="DesktopFolder">
<Component Id="ApplicationDesktopShortcut" Guid="*">
<Shortcut Id="MyClient_DesktopShortcut" Name="My Client"
Description="My Client" Target="[INSTALLFOLDER]MyClient.exe"
WokingDirectory="INSTALLFOLDER" />
<RegistryValue Root="HKCU" Key="Software\MyServices\My Client\DesktopShortcut"
Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
Thanks
Jason

Get WiX / MSI to install some registry always, preserve some pre-existing ones

I have a WiX installation that also needs to write some registry keys, and I was wondering if there's a way to tell WiX/MSI to
only create a key if it doesn't exist yet
always create/overwrite another key, even if it exists
I tried something like this:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="TestRegistry" Language="1033" Version="1.0.2"
Manufacturer="Myself" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes"
InstallScope="perUser" InstallPrivileges="limited" />
<MajorUpgrade DowngradeErrorMessage="A newer version installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="TestRegistry" Level="1">
<ComponentRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="dirManufacturer" Name="Manufacturer">
<Directory Id="INSTALLFOLDER" Name="TheProduct">
<Component Id="ProductComponents" Guid="*" DiskId="1">
<RegistryKey Root="HKCU" Key="Software\Manufacturer\TheProduct"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="Install Directory"
Value="[INSTALLFOLDER]" KeyPath="yes" />
<RegistryValue Type="string" Name="Product Version"
Value="[ProductVersion]" />
<RegistryValue Type="string" Name="Default Language" Value="en" />
<RegistryValue Type="string" Name="Web Site URL"
Value="https://product.manufacturer.info/" />
</RegistryKey>
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>
</Wix>
and here, I'd like to always overwrite the Install Directory and Product Version keys with current values, but I would like to preserve other settings, like Default Language.
Is there any way to do this?
Right now, when I install 1.0.0 fresh on a new system, it creates the registry keys alright. When I uninstall it, they're gone - so far, so good.
But when I installed v1.0.1 and then - without uninstalling v1.0.1 - installed v1.0.2 on top of this, ALL the defined registry keys were updated and contained the default values defined in the WiX script - the changes I had made manually were wiped out.
You will need to break the registry values out to there own components and set the NeverOverwrite attribute on them
<Component Id="DefaultLangaugeComponent" Guid="*" NeverOverwrite="yes">
<RegistryKey Root="HKCU" Key="Software\Manufacturer\TheProduct"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="Default Language" Value="en" />
</RegistryKey>
</Component>

How to write production version to registry

I want to write the installed version to registry using WiX. Here is the WiX code of mine:
<Product Id="B20795DC-5462-4DE6-B629-8C034D114D3C" Name="ProductName" Language="1033" Version="1.1.3" Manufacturer="Corp" UpgradeCode="8f5c57ff-71fe-4fc6-9400-9bbbb76b4262">
....
<Component Id="ProgramRegistry">
<RegistryKey Id="RegInstallDir" Root="HKLM" Key="Software\[Manufacturer]\[ProductName]" Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="InstallVersion" Value="[Version]"/>
</RegistryKey>
</Component>
It creates a key named "InstallVersion" but the value is empty.
My question is how to write the product version into registry, the expected value should be the same as the version attribute in <Product> tag. (1.1.3)
The ProductVersion property contains the value you're looking for.
You can use ProductVersion property, the way #Stephen suggests. Alternatively, you can use the following approach:
define the version in a WiX variable
reference this variable in both Product element and RegistryValue element
set the product version in your build script and pass it to WiX compiler
Hence, your sample might look like this:
<Product Id="B20795DC-5462-4DE6-B629-8C034D114D3C" Name="ProductName" Language="1033" Version="$(var.Version)" Manufacturer="Corp" UpgradeCode="8f5c57ff-71fe-4fc6-9400-9bbbb76b4262">
....
<Component Id="ProgramRegistry">
<RegistryKey Id="RegInstallDir" Root="HKLM" Key="Software\[Manufacturer]\[ProductName]" Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="InstallVersion" Value="$(var.Version)"/>
</RegistryKey>
</Component>
</Product>
And somewhere in the build script (let's pretend, it is NAnt):
<candle out="${build.fodler}" rebuild="true" extensions="${build.extensions}" exedir="${wxs.dir}">
<defines>
...
<define name="Version" value="1.1.3" />
...
</defines>
<sources basedir="${paths.wxs}">
<include name="**.wxs"/>
</sources>
</candle>

Wix:How Can I Create Shortcut Without Registry

In our project, we are going to remove registry entries to make non-admin users able to install it.
Our current code is as follow, I tried to comment out the section from the XML file but failed.
Is there any chance that we can create the shotcut without registry key? thanks.
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="C85221B1-70CA-455D-B322-093543BD4DF0">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="$(var.ProductName)"
Description="$(var.ProductDescription)"
Target="[APPLICATIONROOTDIRECTORY]OMOffline.exe"
WorkingDirectory="APPLICATIONROOTDIRECTORY" />
<Shortcut Id="RemoteAssistance"
Name="Request Remote Assistance"
Description="Starts Remote Assistance and creates a password-protected RA ticket that is attached to a new Remote Assistance invitation. The User must enter the e-mail address of the Helper in the To field to send the message to the Helper."
Target="[SystemFolder]MSRA.exe"
Arguments="/email"/>
<Shortcut Id="UninstallProduct"
Name="Uninstall $(var.ProductName)"
Target="[SystemFolder]msiexec.exe"
Arguments="/x [ProductCode] SQLSERVER="[SQLSERVER]""
Description="Uninstalls $(var.ProductName)" />
<RemoveFolder Id="RemoveApplicationProgramsFolder"
Directory="ApplicationProgramsFolder"
On="uninstall"/>
<!--<RegistryValue Root="HKCU" Key="Software\$(var.ProductManufacturer)\$(var.ProductName)" Name="shortcutsinstalled" Type="integer" Value="1" KeyPath="yes"/>-->
</Component>
</DirectoryRef>
<DirectoryRef Id="DesktopFolder">
<Component Id="DesktopShortcut" Guid="C03900DF-FFD8-44B8-AA42-1BC72BB9E1F4">
<Shortcut Id="ApplicationDesktopShortcut"
Name="$(var.ProductName)"
Description="$(var.ProductDescription)"
Target="[APPLICATIONROOTDIRECTORY]OMOffline.exe"
WorkingDirectory="APPLICATIONROOTDIRECTORY" />
<!--<RegistryValue Root="HKCU" Key="Software\$(var.ProductManufacturer)\$(var.ProductName)" Name="desktopshortcutinstalled" Type="integer" Value="1" KeyPath="yes"/>-->
</Component>
</DirectoryRef>
HKCU is per-User entry, That should not Interfere with your goal of Making per-user Install. You can use http://blogs.msdn.com/b/rflaming/archive/2006/09/30/778690.aspx to make a package per-user Installable.
To answer your question, I tried installation without registryvalue. Program Was allowed to build (with ICE38/ICE41 error), I was able to see the link post Installation of MSI