Search code examples
wixcustom-actionwix3.5

Invoking Data Protection API from within a CustomAction


I am trying to run some unmanaged code from a C# ca within WIX. I have a wrapper around the CryptProtectData function, this code works fine if run from an admin prompt. I have scheduled the ca as deferred hoping it would run during the elevated session however it fails in this context.

The scheduling is as follows:

<CustomAction Id="SetCustomActionDataValue" Property="EncryptValues" Value="foo=bar;...;" />
<CustomAction Id="EncryptValues" BinaryKey="InstallerCustomAction.CA.dll" DllEntry="EncryptValues" Execute="deferred" Impersonate="no" HideTarget="no" Return="check" />

<InstallExecuteSequence>
  <Custom Action="SetCustomActionDataValue" After="InstallFiles" />
  <Custom Action="EncryptValues" After="SetCustomActionDataValue" />
</InstallExecuteSequence>

What needs to be done to allow something like this to run during the installer, preferably after the files and registry entries are committed to the system?


Solution

  • Do you have any logging in your CA? Can you confirm that your CustomActionData made it over?

    One thing you might try is to wire this up as a simple console app and use PSExec to invoke a cmd.exe prompt as SYSTEM.

    I've never used this API but the comment "Typically, only a user with the same logon credential as the user who encrypted the data can decrypt the data." makes me think that this might not run well as SYSTEM. This article seems to confirm that. http://www.obviex.com/samples/dpapi.aspx

    FWIW, I'm not sure what you are trying to achieve but I'd consider moving it from the installer to the application if possible. Installers are generally best kept simple and reliable.