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

こ雲淡風輕ζ 提交于 2019-12-02 21:07:08

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

  1. 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'>
    
  2. 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" />
    
  3. 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>
    
  4. 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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!