Execute only if elevated privilege using DetectCondition for ExePackage action

Viewed 26

perUser Installation if use runs the bootstrap-installer.exe as administrator(right-click and run as Administrator).

the below action should check(privilege), run and install otherwise skip installation. Please help me with the condition how to check the installer has privilege.

<ExePackage Id="w1Uninstaller" DetectCondition="??" UninstallCommand="/S" After="InstallerREC"
              SourceFile="..\..\build\install.exe" PerMachine="no" Cache="no" Vital="no" Compressed="yes" DisplayName="Project Filters" /> 
1 Answers

You can use managed code custom action to set property. Same property could be used in launch condition.

        WindowsIdentity identity = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(identity);

        bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);

        if (isElevated)
        {
         // Set property here
        }
Related