ManagedProject cannot acquire elevated privileges properly
Background
I am trying to replace a Project definition with a ManagedProject definition, so I can use the AfterInstall event to modify some configuration file.
Here is the starting code that works fine:
var project = new Project
{
OutDir = "output",
Name = projectName,
Platform = Platform.x64,
UI = WUI.WixUI_Minimal,
MajorUpgrade = MajorUpgrade.Default,
GUID = new Guid("(redacted)"),
BannerImage = @"..\..\install\Resources\Icons\BannerImage.png",
BackgroundImage = @"..\..\install\Resources\Icons\BackgroundImage.png",
Version = Assembly.GetExecutingAssembly().GetName().Version.ClearRevision(),
ControlPanelInfo =
{
Manufacturer = Constants.MANUFACTURER,
ProductIcon = @"..\..\install\Resources\Icons\ShellIcon.ico"
}
};
which is then used in:
void BuildMsi()
{
project.InstallScope = InstallScope.perMachine;
project.OutFileName = $"{outputName}-{project.Version}";
project.Dirs =
[
new InstallDir(@"C:\",
new Dir(@"%ProgramFiles%\ABC\Revit\Addins\", wixEntities_Assemblies),
new Dir(@"%CommonAppDataFolder%\Autodesk\Revit\Addins\", wixEntities_AddinFile))
];
project.BuildMsi();
}
The above code works, but to use the AfterInstall event, I need to instantiate the project as a ManagedProject.
The Modification So I started with a single line change:
var project = new ManagedProject
but I ran into multiple issues.
Minor Problem
As soon as I do the above, I run into:
WixSharp.ValidationException: Project.BackgroundImage has incompatible (with ManagedUI default dialogs) aspect ratio. The expected ratio is close to W(156)/H(312). The background image (left side banner) in ManagedUI dialogs is left-docked at runtime and if it's too wide it can push away (to right) the all other UI elements. You can suppress image validation by setting Project.ValidateBackgroundImage to 'false'.
which is not a big deal and I can do:
var project = new ManagedProject
{
[...]
ValidateBackgroundImage = false,
};
Note that I do have the right size image, and if instead of suppressing the verification, I change the aspect ratio, the installer stretches the image to the previous size.
Major Problem The installer builds successfully, but does not seem to get the elevated privileges right. So when I run it normally, it "ends prematurely" without telling what really happened.
I tweaked the user account control settings, so the prompt for elevated privileges does show up, but does not appear to do anything. Adding InstallPrivileges = InstallPrivileges.elevated does not help, perhaps because I already have project.InstallScope = InstallScope.perMachine;. The only way I can run this successfully is doing msiexec /i Installer.msi from a command prompt with elevated privileges.
Is this expected? Can I please get some eyes on this issue? Thanks!
morning, questions over questions.
- Which Version of Managed Project do you use - v3 or v4 ?
- Looks like your project decription seems not right. Is issue same if you create just empty managedproject from managed project template ? if yes, your outgoing msi seems broken, and if not, maybe user somehow has windows UAC issue.
- Your backgroundimages should be in right ratio. Is predefinied by wix toolset self. All forms has to be in special ratio H x W . Message say it all.
"... So when I run it normally, it "ends prematurely" without telling what really happened. " any specials errors in wixsharp log ? Normally shows error for example 1613 for issues in msi and so on.. Any Entries in Windows Log for your installation ? Windows log all msiexex issues in log , maybe Log Entry can show, why your msi has problem with installation.
i just tested fresh managed ui template project v3 and msi . UAC appears, but after adding credentials , setup ends permanently. With Log Info : Failed to create Temp Folder : exitcode 5. this test was on normal working station. on Testsystem with admin rights, works -> ok. Something prevents msi file and uac in windows to proceed futher in installation. Maybe some windows updates KBXXXXXXX or user has no rights to install. Also Antivirus can be issue. 🤔🤔🤔
In Wixsharp Log : Info: === Logging started: 02.04.2025 10:06:00 === CommonData: Message type: 0, Argument: 1033 CommonData: Message type: 1, Argument: MyProduct ActionStart: Action 10:06:00: INSTALL. Info: Action start 10:06:00: INSTALL. CommonData: 1: 0 2: 1033 3: 1252 CommonData: 1: 0 2: 1033 3: 1252 CommonData: 1: MyProduct Info: === Logging started: 02.04.2025 10:06:05 === CommonData: Message type: 0, Argument: 1033 CommonData: Message type: 1, Argument: MyProduct ActionStart: Action 10:06:05: INSTALL. Info: Action start 10:06:05: INSTALL. InstallStart: 1: MyProduct 2: {0581BAD2-6A96-4F1F-887B-27DF61E52D77} ActionStart: Action 10:06:05: WixSharp_InitRuntime_Action. Info: Action start 10:06:05: WixSharp_InitRuntime_Action. Info: SFXCA: Failed to create temp directory. Error code 5 Info: CustomAction WixSharp_InitRuntime_Action returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Info: Action ended 10:06:05: WixSharp_InitRuntime_Action. Return value 3. Info: Action ended 10:06:05: INSTALL. Return value 3. InstallEnd: 1: MyProduct 2: {0581BAD2-6A96-4F1F-887B-27DF61E52D77} 3: 3 CommonData: 1: 2 2: 0 CommonData: 1: 2 2: 1 Info: Action ended 10:06:05: INSTALL. Return value 3.
Thanks for looking.
I am using ManagedProject from the latest nuget release 1.26. There are no issues when I use the Project class to instantiate, and that is what is puzzling. Maybe I am missing some required additional configuration needed for ManagedProject right out of the box?
And I see no specific errors in during msi build time, and also nothing in Windows logs. I can check this again later today though to make sure.
Also for the image, should Project and ManagedProject behave differently here? And I get better results when I use the same image aspect ratio that Project is happy with.
morning, AFAIK ManagedProject class is better for purpose if you want to have custom UI with custom dialogs from wixsharp. Also here can you set your custom images on each dialog, in normal project you cant. here you cant specify UI and got stock msi UI as standard.
There are a few considerations here:
-
ProjectvsManagedProjectManagedProject is always preferred because of its better dev experience. The only difference between these two is thatManagedProjectalways add a hidden managed custom action that facilitates those runtime CLR events (e.g. BeforeInstall, AfterInstall) -
Info: SFXCA: Failed to create temp directory. Error code 5This is a WiX error that I think has been fixed in their latest release. Basically, at runtime WiX SFXCA layer is trying to write to the location that it has no permissions for. If you useProjectas you do, then WiX SFXCA layer is simply not initialized. That's why it seems like it is something that is introduced byManagedProject. However, if you add custom actions to theProject, the same problem will most likely surface.
Thanks for Explanation, @oleg-shilo. 2 Questions here : a) wix 3.X is EOL , i have already installed 3.14, do i have to update to Version 5 or something ? , b) Cant we get Message at end of Installer or iuser changed Path to installdir and has no acceess to it ? Like User User1 doesnt have permission to install in this path, on Installdir Path Dialog or End of installation process ? MSI or Bootstrapper Applcaion ?
i found https://learn.microsoft.com/en-us/windows/win32/msi/windows-installer-error-messages and error 1303 - The Installer has insufficient privileges to access this directory, --- whaterever path ist.
do i have to update to Version 5 or something ?
Yes if you want to continue using WiX updates. I also stopped wix3 stream of WixSharp. However, if you have a working project based on WiX3 and you have no intention of changing it, then you can keep this project as is.
Cant we get Message at end of Installer or iuser changed Path to installdir and has no acceess to it?
You can. You can check it even before starting the installation. If you have your project created from the template with all dialogs source code, then you can simply do the check when user changed the dir.
Though the error that was discussed in this thread is not related to the INSTALLDIR but to the temporary dir that WiXC runtime creates to extract all assemblies before their execution at runtime:
Info: SFXCA: Failed to create temp directory. Error code
This is something that WiX is responsible for and as far as I know WiX had a fix for it.
Yep, if you follow this discussion "https://github.com/oleg-shilo/wixsharp/issues/1593" you will see this comment:
@nefarius indicated that WiX is broken and one needs to migrate to the WiX4 or higher.
I have since made the jump to v4/v5 to not sink any more time into trying to solve this btw.