6

I have created a custom action:

<CustomAction Id='AddEventLog' BinaryKey='CustomActionEventLog.dll' DllEntry='AddEventLog' Return="check" Execute="immediate"/>

Install sequence

<Custom Action="AddEventLog" Before="InstallFinalize"  />

My installer does pop up and say that it needs admin rights to run. Which I grant it.

InstallPrivileges='elevated' InstallScope='perMachine' AdminImage='yes'

However when it runs the custom action it doesn't work because its not running as administrator.

I even tried adding the following to app.manifest on my custom action project dll. It didn't help.

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

I have scoured all the tutorials and forum posts I can find on this subject. Noting has worked yet.

If anyone has any better tags for this please feel free to add them I have been struggling with this all day.

Update for clarification:

While my customAction does work with EventLog I am not using http://schemas.microsoft.com/wix/UtilExtension Util:EventSource. It is a genral question can you even force a customAction to run as administrator?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • What does your custom action do? There may be wix extensions that could be useful which sidestep your issue (ie. http://stackoverflow.com/questions/58538/how-do-you-create-an-event-log-source-using-wix). – Patrick Allwood May 23 '16 at 12:39
  • Adds and Removes a new event log and event source. To System.Diagnostics.EventLog I was unable to find an existing extension for this. – Linda Lawton - DaImTo May 23 '16 at 12:42
  • Ok, so while this doesn't directly answer your posted question, I think you're looking for util:EventSource (http://wixtoolset.org/documentation/manual/v3/xsd/util/eventsource.html), you need to supply the correct EventLogMessages.dll for the framework version you're targetting, explanation of how to do so using the NetFx extension is here (http://stackoverflow.com/questions/12433883/how-to-create-a-net-event-log-source-using-wix) – Patrick Allwood May 23 '16 at 13:06
  • fortunately no it doesn't directly answer my question. My customaction works as long as the user has executed the msi from a cmd prompt that was logged in as admin, if its a normal user it does not work even though the installer prompts for access. Again I am not using Util.EventSource I am using a custom developed customaction that needs to have admin permissions. Is there a way of sending the permissions to the custom action or maybe it has something to do with the fact that I am running it before installFinalize. – Linda Lawton - DaImTo May 23 '16 at 13:24

2 Answers2

3

To run any custom action with administrator privileges you must run the custom action during the Server portion of the installation. ie: it must be a deferred custom action. Otherwise, I think you get a consent.exe message box asking for administrator privileges.

All msi installs work in two parts, Client and Server portions of the install. The Client portion is where you see the UI and set properties that may determine where things get installed and what gets installed (they must be marked Secure for the Server portion of the install to have access to them). The Server portion is what actually puts the files on your system. This always (??) requires administrator privileges because it can be writing stuff into Program Files and other protected file locations.

These custom actions must be marked "Execute='deferred'" and must also be scheduled between the InstallaInitialize and InstallFinalize.

Also to note, if you want to use values of any properties from your installation within the custom action you need to use a separate custom action which sets a specially named property with a special format. You then get the property values in your custom action querying the CustomActionData of the session object. There are lots of examples out there you can find.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Brian Sutherland
  • 4,698
  • 14
  • 16
2

Disclaimer, I've not done this previously, and personally I'd take the other approach of using the wix extensions, but you should be able to give elevated permission to your custom actions by using deferred execution and not impersonating the current user. So in your case, Execute="immediate" is what's standing in your way.

<CustomAction Id="MyCustomAction" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no"/>


<!-- -or- -->


<CustomAction Id="MyCustomAction" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="commit" Return="check" Impersonate="no"/>

Source

Patrick Allwood
  • 1,822
  • 17
  • 21