Tag Archives: wix

How to run WIX bootstrapper application UI with elevated privileges?

WIX bootstrapper application (BA) can easily determine if it runs as admin with the following code:

using System;
using System.Diagnostics;
using System.Security.Principal;

static bool IsAdmin()
{
    WindowsIdentity id = WindowsIdentity.GetCurrent();
    WindowsPrincipal principal = new WindowsPrincipal(id);
    return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

and if it does not, run a new instance as admin and exit:

static void RunAsAdmin()
{
    ProcessStartInfo proc = new ProcessStartInfo
    {
        UseShellExecute = true,
        WorkingDirectory = Environment.CurrentDirectory,
        FileName = Process.GetCurrentProcess().MainModule.FileName,
        Verb = "runas"
    };

    Process.Start(proc);
}

(more…)

How to check .NET Framework version with WIX installer

WIX has NetFxExtension with NetFx4XXXX packages, so .NET Framework 4.6, for example, can be installed with the single line of code:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">
    <Bundle Name="My App">
        ...
        <BootstrapperApplicationRef Id="ManagedBootstrapperApplicationHost">
            <Payload SourceFile="$(var.MySetupUI.TargetPath)"/>
            <Payload SourceFile="$(var.MySetupUI.TargetPath).config"/>
            <Payload SourceFile="$(var.MySetupUI.TargetDir)BootstrapperCore.dll"/>
            <Payload SourceFile="$(var.MySetupUI.TargetDir)BootstrapperCore.xml"/>
            <Payload SourceFile="BootstrapperCore.config"/>

            <Payload SourceFile="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ServiceProcess.dll"/>
            <Payload SourceFile="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Configuration.Install.dll"/>
            <Payload SourceFile="C:\Program Files (x86)\WiX Toolset v3.11\SDK\Microsoft.Deployment.WindowsInstaller.dll"/>
        </BootstrapperApplicationRef>

        <Chain>
            <PackageGroupRef Id='NetFx46Web'/>
            <MsiPackage SourceFile="$(var.MyAppSetup.TargetPath)" Id="InstallationPackageId" Cache="yes" Visible="no"/>
        </Chain>
    </Bundle>
</Wix>

(more…)

A simple WIX installer that runs custom actions on install and uninstall.

Below I provided the source code of WIX installer that shows the license, installation directory and runs custom actions on install and uninstall:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="My Game" Language="1033" Version="1.0.0.0" Manufacturer="SharLines Corporation" UpgradeCode="...">
        ...    

        <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" ></Property>
        <WixVariable Id="WixUILicenseRtf" Overridable="yes" Value="License.rtf"/>
        <UIRef Id="WixUI_InstallDir"/>

        <InstallExecuteSequence>
            <Custom Action="InstallService" After="InstallFiles">(NOT Installed) AND (NOT REMOVE)</Custom>
            <Custom Action="UninstallService" After="InstallInitialize">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
        </InstallExecuteSequence>
        <CustomAction Id="InstallService" Return="check" Impersonate="yes" Execute="deferred" Directory="INSTALLFOLDER" ExeCommand="[INSTALLFOLDER]$(var.MyService.TargetFileName) parameters..."/>
        <CustomAction Id="UninstallService" Return="check" Impersonate="yes" Execute="deferred" Directory="INSTALLFOLDER" ExeCommand="[INSTALLFOLDER]$(var.MyService.TargetFileName) parameters..."/>
    </Product>
    ...
</Wix>

MyService is project referenced by my wixproj in VS2015. If Impersonate=”yes” the command is run as the current user, if “no”, the command is run as “NT AUTHORITY\SYSTEM“. INSTALLFOLDER is defined as follows:

(more…)