Install a pfx certificate in a users store in Windows using WiX - installation

Please, can someone provide me with a WiX snippet or solution for the mentioned scenario. I need to include the pfx file in the WiX msi and the user will download my msi to his machine via the internet explorer and Click install and I need also the certificate to be installed on his machine.

You need the Certificate element. It is part of the IIS extension for wix, but can be used for non-IIS related installations also.
You need to
declare a prefix for the iis namespace, for
example like this in the root Wix element:
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'
xmlns:iis='http://schemas.microsoft.com/wix/IIsExtension'>
Embed the PFX file as a binary
stream in your install package. Add
a Binary element under the
product element like this:
<Binary Id="MyCertificateBinaryStream"
SourceFile="c:/path/to/mycertificate.pfx" />
Declare a component with a <iis:Certificate> element, for
example like this. Look at the
documentation, you need to fill in some
more attributes. Note that you don't need CertficatePath if you use the BinaryKey attribute.
<Component Id="MyCertificateComponent" Guid="MY-GUID-HERE">
<iis:Certificate Id="MyCertificate"
BinaryKey="MyCertificateBinaryStream"
... some more attributes ...
/>
</Component>
Activate the IIS extension by adding
the option -ext WixIISExtension
option when invoking the wix command line tools. If you use visual studio, this is just a matter of adding a reference in your wix project to WixIISExtension.

To expand on the answer a little, the following set of attributes worked for me:
<iis:Certificate
Id="My.Certificate"
StoreName="root"
Overwrite="yes"
Name="My Friendly Certificate Name"
Request="no"
BinaryKey="MyCertificate.Binary"
StoreLocation="localMachine" />
Where the <Product> element contained a <Binary> child as follows:
<Binary
Id="MyCertificate.Binary"
SourceFile="$(var.ProjectDir)MyCertificate.pfx" />
(I included the PFX file within my WiX project).

Related

WIX Change Product Name and Install directory from command line parameters

I ran into a typical scenario where it required to change product name as supplied from command line parameters as below
MSBuild.exe ApplicationSetup.wixproj /p:AssemblyTitle=%USER_SPECIFIED_NAME% /p:ProductVersion=%VERSION% /p:ProductCode=%PRODUCT_CODE% /p:UpgradeCode=%UPGRADE_CODE% /t:Clean;Rebuild"
I am using those supplied parameters in .wxi file. as below :
<Product Id="$(var.ProductCode)" Name="$(var.AssemblyTitle)" Language="4"
Version="$(var.BuildVersion)"
Manufacturer="!(loc.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
This code compiles successfully. But the name of product in add/remove program is not reflecting correctly. I read that Product name cannot be supplied directly, it should be hard coded.Please advise on this.
Another typical requirement is to have multiple version installed of same product on a machine. I somewhat achieved this by doing following change in Product tag in .wxi file
<Product Id="*" Name="$(var.AssemblyTitle)" Language="4"
Version="$(var.BuildVersion)"
Manufacturer="!(loc.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
Now here come the issue that second installation will overwrite the file generated during first installation. So it is required to change install directory dynamically.
I have posted this after struggling for couple of days and tried many solution, but all in vain. Any help will be highly appreciated.

WIX: reference a source file but not install it to the destination computer

I'm compiling an installer using Wix, and I'm trying to make it install a scheduled task. I've created an XML file with the details of my scheduled task (called BackupComplete.xml - using the export function in scheduled tasks). Now I want to reference it in a CustomAction so that at the end of the installation, the scheduled task is added.
Right now I have this bit:
<CustomAction Id="CreateScheduledTask" Return="check" Directory="Scripts" ExeCommand="[SystemFolder]schtasks.exe /Create /XML BackupComplete.xml" />
But how do I reference my BackupComplete.xml file? I don't want BackupComplete.xml to be installed to the desination computer, it should only be included in the source .cab file so my CustomAction can read it.
I could add my scheduled task XML file like this:
<File Id="taskxml" Source="src\BackupComplete.xml" />
Inside a Component, but that'll install BackupComplete.xml on the target computer, which is what I want to avoid...
This is my entire WIX XML: http://pastebin.com/wFWd1zVc
Thanks,
The following approach is often used in the similar situations:
add your temporary files to the Binary table. Use <Binary> element for this
in a deferred custom action:
extract the file
perform necessary actions
remove the file

How do I make a WiX installer force VS to install templates?

I've got a WiX installer that is meant to update VS 2010 templates after installing them. The code I'm using is as follows:
<CustomAction
Id="InstallTemplates"
ExeCommand=""[VISUALSTUDIODIR]devenv.exe" /installvstemplates"
Directory="VISUALSTUDIODIR"
Execute="commit"
Return="check"
HideTarget="no"
Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="InstallTemplates" Before="InstallFinalize"></Custom>
</InstallExecuteSequence>
In the above, VISUALSTUDIODIR refers to the correct location, and templates are correctly deployed. However, it seems that the command does not get called, so no templates are actually installed. What am I doing wrong?
WiX has built-in functionality to do that. Add a reference to WixVSExtension.dll and add the following authoring:
<CustomActionRef Id="VS2010InstallVSTemplates" />
Make sure that VISUALSTUDIODIR is an actual directory in your MSI package (it's saved in Directory table). This is a requirement for this type of custom action.
Also, try creating an installation log and search for your custom action to see what happens.

WIX public properties displayed on the UI

We have an installer created using WIX. As part of this install we would like to show the currently selected installation path. I thought this would be much easier than it is, apparently. I have tried using the a public property "INSTALLDIR" (I know we're not using Installshield, this value is a directory ID.)
<Directory Id="INSTALLDIR" Name="AcmeInc">
I can also see where INSTALLDIR gets set when running the install
MSI(EC:6C) Dir (target): Key: INSTALLDIR , Object: C:\Program Files\AcmeInc\
but when I try to show this on the UI using a Text attribute I get "...\." which doesn't even look to be a relative path.
I know there has got to be something simple I'm missing here.
Assuming you're using WiX 3.5 and the MajorUpgrade element - the following should work (I usually use APPLICATIONFOLDER instead of INSTALLDIR - but they should be interchangeable).
First, let's set ARPINSTALLOCATION as described on http://robmensching.com/blog/posts/2011/1/14/ARPINSTALLLOCATION-and-how-to-set-it-with-the-WiX-toolset
<SetProperty Id="ARPINSTALLLOCATION" Value="[INSTALLDIR]" After="CostFinalize" />
Now lets set the selected installation folder to the previous installation folder, if one previously existed that is.
<Property Id="INSTALLDIR" Secure="yes">
<RegistrySearch Id="FindInstallLocation"
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\[WIX_UPGRADE_DETECTED]"
Name="InstallLocation"
Type="raw"
Win64="yes" />
</Property>
And during the UI sequence, we want this value to be set 'early'
<InstallUISequence>
<AppSearch After="FindRelatedProducts"/>
</InstallUISequence>

Why is _wixCert_{0-9} added to certificate friendly name by WiX?

I am installing some certificates into localStore and for some strange reason all those certs are suffixed with "_wixCert_0" or "_wixCert_1". I've tried to manually remove all the certificates prior install to make sure that there's nothing left, but it still happens. What could be the reason?
This is how i've defined the certificates:
<Component Id="MyCert_file" Guid="*">
<File Id="MyCert" Name="MyCert.crt" Source="$(var.CertSourceDir)\MyCert.crt" />
</Component>
<Component Id="MyCert" Guid="..." KeyPath="yes">
<iis:Certificate Id="MyCert"
Name="MyCert"
Request="no"
StoreLocation="localMachine"
StoreName="ca"
Overwrite="yes"
BinaryKey="MyCert"
/>
</Component>
The certificates get added to the certstore, but they have friendly name like "MyCert_wixCerts_0" and so on. I cannot figure it out why is it happening.
Anyone else does?
In the WiX source code in src\ca\serverca\scaexec\scacertexec.cpp the InstallCertificatePackage method adds "wixCert" and an increasing unique number to the certificate name before installing it. It looks to be to make sure the name is unique in the certificate store.
The UninstallCertificatePacket method tries to find certificates using the CERTNAME_wixCert_ prefix to find the certificates to uninstall.
There are logging messages in the code that show the certificate names it is installing/uninstalling with the extra stuff added to the name.

Resources