Search code examples
c#.netwix

Adding Custom Action to WiX Installer




Im trying to run a custom command in the cmd using WiX Installer.
I make use of a include file in the Product.wxs wich is correctly consumed throughout the installation.

I have 3 Custom actions and 2 of them are working fine. The one that seems not be working is:

<CustomAction Id='AddDefaultDomain'
        Directory='TARGETDIR'
        Impersonate="no"
        Execute="immediate"
        ExeCommand="C:\windows\system32\inetsrv\appcmd.exe set config /section:basicAuthentication /defaultLogonDomain:[%USERDOMAIN]  /commit:apphost"
        Return="asyncNoWait" />

The installer runs correctly and when I call AppCmd through a cmd windows and Copy->Paste the 'ExeCommand' in the cmd and execute it, it just works fine.

Probably this is something simple but for now I do not understand why it is not working.
All help is appreciated.

Full Include File

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <!-- Create Scheduled Task -->
  <InstallExecuteSequence>
    <Custom Action="CreateScheduledTaskGoogleService" After="InstallFiles">NOT Installed</Custom>
    <Custom Action="CreateScheduledTaskGoogleServiceId" After="CostFinalize">NOT Installed</Custom>
    <!-- Add Defualt DOmain -->
    <Custom Action="AddDefaultDomain" After="CostFinalize">NOT Installed</Custom>

  </InstallExecuteSequence>
  <CustomAction Id="CreateScheduledTaskGoogleService" Return="check" Impersonate="no" Execute="deferred" BinaryKey="WixCA" DllEntry="CAQuietExec" />
  <CustomAction Id="CreateScheduledTaskGoogleServiceId" Property="CreateScheduledTaskGoogleService" Execute="immediate" Value="&quot;[SystemFolder]SCHTASKS.EXE&quot; /CREATE /TN &quot;ActaNet Control - Google Sync&quot; /XML &quot;[INSTALLFOLDERPROGRAMFILESGOOGLE]ScheduledTask.xml&quot;" />

  <!-- DOES NOT SEEM TO BE WORKING! -->
  <CustomAction Id='AddDefaultDomain'
        Directory='TARGETDIR'
        Impersonate="no"
        Execute="immediate"
        ExeCommand="C:\windows\system32\inetsrv\appcmd.exe set config /section:basicAuthentication /defaultLogonDomain:[%USERDOMAIN]  /commit:apphost"
        Return="asyncNoWait" />

  <!-- Delete Scheduled Task -->
  <InstallExecuteSequence>
    <Custom Action="TaskDeleteGoogleService" Before="CreateScheduledTaskGoogleService">REMOVE="ALL"</Custom>
  </InstallExecuteSequence>
  <CustomAction Id="TaskDeleteGoogleService" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no" ExeCommand="SCHTASKS.EXE /DELETE /TN &quot;ActaNet Control - Google Sync&quot; /F" />
</Include>

Solution

  • The very first thing I would do is to confirm that the command is actually being executed. Make use of a tool such as Process Monitor to confirm this.

    Once this is done, I would see if the command is modifying something on the target system which would require elevated privileges to do so. If so,i would change the value of the Execute attribute to "deferred" and see if it works. It seems like you are trying to change something on the target system using an immediate mode custom action. Marking the action as deferred would also require you to place the action between "InstallInitialize" and "InstallFinalize".

    In your present case, you are trying to launch the exe in immediate mode. Immediate mode impersonates the logged on user, hence in UAC environments, any custom action which modifies the target system can fail.