WiX, UAC, managed custom action and impersonation
Asked Answered
E

2

11

I have built a Windows Installer package using WiX 3.6 that embeds a custom managed (C#) action.

At this stage, the installation requires that

  1. The installer be run using a specific local administrator account (in this case, the SharePoint installer account, which is a local administrator)
  2. User Account Control be disabled

There really isn't a way I can bypass requirement #1, because the managed action can only perform certain steps if it runs in the context of the SharePoint installer account.

I would like to remove requirement #2 and let the installer properly run even if UAC is enabled.

I've researched the issue quite extensively but still can't get it to work. I have set InstallScope="perMachine" in my package, which seems to properly prompt for UAC elevation, but the installer still fails with the infamous 2869 error.

The main problem is that my custom action is configured with Impersonate="yes" because it has to run in the context of the current user, not the local administrator account. When I search online, almost all "fixes" point to Impersonate="no" in the custom action, but that's not an option for me.

My question therefore is: is there a way to run a custom managed action with the identity of the current user without requiring UAC to be completely disabled?

Evolve answered 16/10, 2012 at 18:4 Comment(2)
Love an answer to this as well.Shamblin
I am trying to do this same thing. The way I'm trying to get around it is creating an EXE that has admin privileges required in the app.manifest (#3915870). I then call that EXE as a type 2 deferred custom action that impersonates the user (https://mcmap.net/q/1019432/-attempting-to-run-embedded-tool-from-wix-msi-for-selective-installation). However, this works on my machine, but I'm having trouble on other machines: it's not even running on other machines as long as the require admin is in the app.manifest. Hope this gives you a good start.Piccoloist
W
7

When you use Impersonate="yes" your Custom action runs without administrative privileges with the credentials of the currently logged user.

When Impersonate="no" your Custom action is run in System context. When running in system context, the custom action has full access to the system.


From WiX CustomAction element documentation, Impersonate attribute:

This attribute specifies whether the Windows Installer, which executes as LocalSystem, should impersonate the user context of the installing user when executing this custom action. Typically the value should be 'yes', except when the custom action needs elevated privileges to apply changes to the machine.

Wasserman answered 20/10, 2012 at 11:18 Comment(6)
I did this, but my application throws a System.UnauthorizedAccess exception. How that could happend, when I have system rights?Beefwood
@AstralisSomnium Try to make sure your custom action is really run with full access. Impersonate="yes" is valid for deferred actions only. In their turn, deferred actions do not have full access to installation properties, you can use only CustomActionData.Wasserman
I think it's actually the reverse. According to WIX documentation: "This attribute specifies whether the Windows Installer, which executes as LocalSystem, should impersonate the user context of the installing user when executing this custom action. Typically the value should be 'yes', except when the custom action needs elevated privileges to apply changes to the machine.' So Impersonate="no" means your action runs as LocalSystem, which has full access to the machine, and Impersonate="yes" means your custom action runs with the privileges of the installing user.Bawd
@Mr.Bungle You're right! I must have confused it with NoImpersonate bit in the MSI tables. Yet this article says the same as I did: Impersonate="yes" runs in system context. Perhaps something has changed…Wasserman
As per the other comment, You have this the wrong way around. Impersonate="no" will run as the system user (NT AUTHORITY\SYSTEM). Please amend or delete your answerRoesler
@Roesler Thanks! I've edited the answer and also added a quotation from WiX documentation.Wasserman
T
2

Where are you referencing the custom action?

Having the .msi running with elevated privileges might not be enough. To be sure that your custom action works with elevated privileges you also have to use a deferred custom action and reference it in the InstallExecuteSequence. This might not solve your problems, but the articles linked at the bottom goes in detail in explaining the UAC logics during an msi installation.

Basically, not everything the installer does carries the privileges with it, an you have to be sure to run the custom action when the installer is using the elevated privileges.

Source: http://blogs.msdn.com/b/rflaming/archive/2006/09/30/uac-in-msi-notes-when-general-custom-action-mitigation-fails.aspx

I hope you find this information useful, I might be of more assistance if you share your custom action code.

Tion answered 13/8, 2014 at 8:41 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Diversion
You're right sorry, edited it with a better answer. I'm new and still learning how to use stackoverflow. Thank you.Tion

© 2022 - 2024 — McMap. All rights reserved.