Search code examples
wixburnelevated-privileges

How do I use burn's new ability to ability to launch an elevated process after installation is complete?


The current set of samples on how to use wix's new ability to run an elevated process through the engine is very sparse, if it exists at all. From the WIP and the schema docs, I can see that I need a minimum of the following:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
    <Bundle Name="..." Version="1.0.0.0" Manufacturer="..." UpgradeCode="*">
      <BootstrapperApplicationRef 
           Id="WixStandardBootstrapperApplication.RtfLicense">
        <bal:WixStandardBootstrapperApplication 
           LaunchTargetElevatedId="LaunchElevatedInstallProc" 
           LaunchArguments="/myarg=1" 
           LicenseFile="license.rtf" />
      </BootstrapperApplicationRef>

      <ApprovedExeForElevation 
          Id="LaunchElevatedInstallProc" 
          Key="SOFTWARE\Company\Product" 
          Value="PathToExeDeliveredByMSI" />

      <Chain>
        <MsiPackage SourceFile="Setup.msi" Compressed="yes" />
      </Chain>
   </Bundle>
 </Wix>

The Key attribute of <ApprovedExeForElevation> makes sense; it's a registry path to the entry that was created in my msi. The Value attribute is the ValueName in the registry that I created, containing the path to the .exe that I delivered in my install:

  <Component Id="Comp_Client_Service.exe" Guid="PUT-GUID-HERE">
    <File Id="my.exe" Name="my.exe" Source="my.exe" KeyPath="yes" />
    <RegistryValue 
         Root="HKLM" 
         Key="SOFTWARE\Company\Product" 
         Name="PathToExeDeliveredByMSI" 
         Value="[INSTALLFOLDER]my.exe" 
         Type="string"/>
  </Component>

Yet, this does not appear to be working. My .exe never launches, and the .log file provides no information that it is even attempting to launch it.

What is this code missing?

EDIT

The only piece of information that the log provides is that it is setting variables:

Initializing string variable 'LaunchTargetElevatedId' to value 'LaunchElevatedInstallProc'
Initializing string variable 'LaunchArguments' to value '/s'


Solution

  • According to the documentation, the TargetPath attribute on the WixStandardBootstrapperApplication must also be set. WixStdBA falls back to launching the exe at this path unelevated if anything went wrong trying to launch it elevated.

    Id of the target ApprovedExeForElevation element.
    If set with LaunchTarget, WixStdBA will launch the application
    through the Engine's LaunchApprovedExe method instead of through ShellExecute.
    

    You also need a button on the Success page with the name LaunchButton in your theme.