Tuesday, 2 August 2011

WIX 3 NETSH CustomAction

I've been writing a WIX 3 installer for a Windows Service with 2 self hosted WCF services. In order to connect to the WCF services, a Namespace reservation must be made using netsh.exe. I wanted to get the WIX installer to perform this operation during installation so decided to use a CustomAction to achieve this. As anybody who uses WIX will know, it is extremely powerful but sparsely documented and quiet frustrating to use. It took a while to get the CustomAction to work, so I thought I'd share the solution:

!-- Custom action to set WCF namespace reservation -->

<CustomAction Id="ListenerServiceAddReservation"
                  Directory="INSTALLLOCATION"
                  ExeCommand="[SystemFolder]netsh.exe http add urlacl url=http://+:8888/ServiceNamespace/TestService/ sddl=D:(A;;GX;;;WD)"
                  Return="asyncWait" />

<CustomAction Id="ListenerServiceDeleteReservation"
                  Directory="INSTALLLOCATION"
                  ExeCommand="[SystemFolder]netsh.exe http delete urlacl url=http://+:8888/ ServiceNamespace/TestService/"
                  Return="asyncWait" />
  
<InstallExecuteSequence>       
    <Custom Action="ListenerServiceDeleteReservation" Before="InstallFinalize">Installed</Custom>
    <Custom Action="ListenerServiceAddReservation" Before="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>

4 comments:

  1. I second this...
    Thank you!

    ReplyDelete
  2. Since adding urlacl requires administrative privilege, is it necessary to add Execute="deferred" to tag?

    ReplyDelete
  3. Erm, not sure, why? I think it was run as admin. I don't reckon deferred elevates the privilege

    ReplyDelete