It's a good question.
I don't have direct experience but... when faced with a similar challenge - install an ISAPI as an IIS Extension onto a particular virtual directory using WiX - I resorted to using custom actions implemented in Javascript, and in one case, VBScript. I found that WiX had some of the things I needed, but finding the correct information was difficult, and not all IIS admin functions are exposed via WiX. Also, not all IIS Admin things are exposed to Javascript, believe it or not. The WMI interface in one case requires a VBArray. !!
Also, within the custom actions, rather than solely relying on the IIS WMI (programming) interfaces, the code sometimes invokes APPCMD.exe to do the actual work. If you pre-req IIS7 then you will have this. Creating a vdir or app with appcmd would be really simple (appcmd add app
or appcmd add vdir
). The hardest part, for me, was wrapping the necessary supporting Javascript and WiX code around it. Here's how I did it.
In the main product.wxs file:
<InstallExecuteSequence>
...
<!-- configure extension if we need it -->
<Custom Action="CA.AddExtension" After="InstallFiles">NOT Installed AND &F.Binary = 3</Custom>
...
</InstallExecuteSequence>
and then there's a separate customactions.wxs file:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<Binary Id="B.JavaScript" SourceFile="CustomActions.js" />
<Binary Id="B.VBScript" SourceFile="MoreCustomActions.vbs" />
<CustomAction Id="CA.EnumerateWebSites"
BinaryKey="B.JavaScript"
JScriptCall="EnumerateWebSites_CA"
Execute="immediate"
Return="check" />
<CustomAction Id="CA.AddExtension"
BinaryKey="B.VBScript"
VBScriptCall="AddExtension_CA"
Execute="immediate"
Return="check" />
....
And then the javascript looked like this:
function RunAppCmd(command, deleteOutput) {
deleteOutput = deleteOutput || false;
LogMessage("RunAppCmd("+command+") ENTER");
var shell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder);
var tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName());
var windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder);
var appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " " + command;
LogMessage("shell.Run("+appcmd+")");
// use cmd.exe to redirect the output
var rc = shell.Run("%comspec% /c " + appcmd + "> " + tmpFileName, WindowStyle.Hidden, true);
LogMessage("shell.Run rc = " + rc);
if (deleteOutput) {
fso.DeleteFile(tmpFileName);
}
return {
rc : rc,
outputfile : (deleteOutput) ? null : tmpFileName
};
}
// GetWebSites_Appcmd()
//
// Gets website info using Appcmd.exe, only on IIS7+ .
//
// This fn always returns site state info with each record.
//
function GetWebSites_Appcmd() {
var ParseOneLine = function(oneLine) {
// split the string: capture quoted strings, or a string surrounded
// by parens, or lastly, tokens separated by spaces,
var tokens = oneLine.match(/"[^"]+"|\(.+\)|[^ ]+/g);
// split the 3rd string: it is a set of properties separated by colons
var props = tokens[2].slice(1,-1);
var t2 = props.match(/\w+:.+?(?=,\w+:|$)/g);
var bindingsString = t2[1];
//say(bindingsString);
var ix1 = bindingsString.indexOf(':');
var t3 = bindingsString.substring(ix1+1).split(',');
var bindings = {};
for (var i=0; i<t3.length; i++) {
var split = t3[i].split('/');
var obj = {};
if (split[0] == "net.tcp") {
var p2 = split[1].split(':');
obj.port = p2[0];
}
else if (split[0] == "net.pipe") {
var p3 = split[1].split(':');
obj.other = p3[0];
}
else if (split[0] == "http") {
var p4 = split[1].split(':');
obj.ip = p4[0];
if (p4[1]) {
obj.port = p4[1];
}
obj.hostname = "";
}
else {
var p5 = split[1].split(':');
obj.hostname = p5[0];
if (p5[1]) {
obj.port = p5[1];
}
}
bindings[split[0]] = obj;
}
// return the object describing the website
return {
id : t2[0].split(':')[1],
name : "W3SVC/" + t2[0].split(':')[1],
description : tokens[1].slice(1,-1),
bindings : bindings,
state : t2[2].split(':')[1] // started or not
};
};
LogMessage("GetWebSites_Appcmd() ENTER");
var r = RunAppCmd("list sites");
if (r.rc !== 0) {
// 0x80004005 == E_FAIL
throw new Exception("ApplicationException", "exec appcmd.exe returned nonzero rc ("+r.rc+")", 0x80004005);
}
var fso = new ActiveXObject("Scripting.FileSystemObject");
var textStream = fso.OpenTextFile(r.outputfile, OpenMode.ForReading);
var sites = [];
// Read from the file and parse the results.
while (!textStream.AtEndOfStream) {
var oneLine = textStream.ReadLine();
var line = ParseOneLine(oneLine);
LogMessage(" site: " + line.name);
sites.push(line);
}
textStream.Close();
fso.DeleteFile(r.outputfile);
LogMessage("GetWebSites_Appcmd() EXIT");
return sites;
}
Maybe you'll find this useful.