Search code examples
c#wixwindows-installerheatwave

UAC prompt at the launch of msi launch with wix toolset by heatwave


I am creating a msi using wix toolset by heatwave and i want to give the UAC prompt right when the msi is launched, right now the UAC is at the end on the install button.

i have tried setting the scope of the package to perMachine as listed below

<Package Name="~Test" Manufacturer="TODO Manufacturer" Version="1.0.0.0" UpgradeCode=GUID Scope="perMachine" >

this did not work so i tried to add a c# action in the ExecuteSequence like below

<InstallExecuteSequence >
<Custom Action="UACPROMPT" Before="CostInitialize" />
</InstallExecuteSequence>

c# code looks like this

using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using WixToolset.Dtf.WindowsInstaller;

namespace UACPrompt
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction2(Session session)
        {
            session.Log("Begin CustomAction1");

            try
            {
                string directory = "C:\\Program Files (x86)\\Folder";
                string filePath = "C:\\Program Files (x86)\\Folder\\initialize.txt";

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                using (StreamWriter sw = new StreamWriter(filePath))
                {
                    sw.WriteLine($"Initializing");
                }
                return ActionResult.Success;
            }
            catch (Exception ex)
            {
                session.Log("ERROR in ShowUACPrompt: " + ex.Message);
                return ActionResult.Failure;
            }
        }
    }
}

this didn't work either so i was looking added this property

<Property Id="installElevated" Value="1" />

But none of these worked

so i was looking if i am doing something wrong or there is a different approach .

Thank You!


Solution

  • The Windows Installer doesn't prompt for elevation until required. To get the behavior you describe using an MSI file, you'll need to open a feature request with Windows.