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>

9 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. This comment has been removed by the author.

    ReplyDelete
  4. Shawn is correct, you need execute=deffered for vista+, I was working ok XP when I wrote this

    ReplyDelete
  5. Impersonate should also be set to "no" for vista+

    ReplyDelete
  6. You're a saint

    ReplyDelete
  7. This is Awesome! I am not familiar with WIX but uses your code get my job done.

    ReplyDelete