MSI installer custom action identity problem

2019-07-18 04:51发布

问题:

I'm creating a custom action that executes a script on a database. The problem is that the connectios uses intergrated security, so when I try to open the connection i get the error: Login Failed for user 'Domain\ComputerName$'.

When i check the identity on the custom action (using System.Security.Principal.WindowsIdentity.GetCurrent()) I always get "NT AUTHORITY\SYSTEM" but I'm running the installer under my account which has enough privileges on the Database.

How can I run the custom action under the real user runnig the msi file or solve this problem in any other way?

回答1:

Well, there's a simple solutions for this but maybe it's not suitable for all cases.

If you set the project property of InstallAllUsers To true, the installer runs with "NT AUTHORITY\SYSTEM" Account, but if you set it to false it runs with the identity of the user who launches the installer.

Setting it to false worked for me, even that I was installing a Windows Service that runs for all users.



回答2:

The short answer is that you're going to need to

  1. Enable 'impersonation' for the custom action.
  2. (On Windows Vista and Windows 7 systems) run the entire installation in an 'elevated' context (i.e. 'Run as Administrator').

How you accomplish #1 depends on what you are using to create the installation package. In order to easily deal with #2, I use a bootstrapper (created with Bootstrapper Manifest Generator) that is configured to run 'elevated'.