Es ist eine gute Frage.
Ich habe keine direkte Erfahrung, aber ... mit einer ähnlichen Herausforderung konfrontiert - installieren Sie eine ISAPI als eine IIS-Erweiterung in ein bestimmtes virtuelles Verzeichnis mit WiX - Ich habe benutzerdefinierte Aktionen in Javascript implementiert und in einem Fall, VBScript. Ich fand, dass WiX einige der Dinge hatte, die ich brauchte, aber die richtigen Informationen zu finden war schwierig, und nicht alle IIS-Admin-Funktionen sind über WiX verfügbar. Außerdem sind nicht alle IIS-Admin-Objekte mit JavaScript konfrontiert, ob Sie es glauben oder nicht. Die WMI-Schnittstelle erfordert in einem Fall ein VBArray. !!
Auch innerhalb der benutzerdefinierten Aktionen, anstatt sich ausschließlich auf die IIS WMI (Programmierung) Schnittstellen zu verlassen, ruft der Code manchmal APPCMD.exe, um die eigentliche Arbeit zu tun. Wenn Sie IIS7 vorschreiben, dann haben Sie dies. Das Erstellen eines vdir oder App mit appcmd wäre wirklich einfach (appcmd add app
oder appcmd add vdir
). Der schwierigste Teil war für mich, den notwendigen unterstützenden Javascript- und WiX-Code darum zu wickeln. Hier ist, wie ich es gemacht habe.
Im Haupt product.wxs Datei:
<InstallExecuteSequence>
...
<!-- configure extension if we need it -->
<Custom Action="CA.AddExtension" After="InstallFiles">NOT Installed AND &F.Binary = 3</Custom>
...
</InstallExecuteSequence>
und dann gibt es eine separate customactions.wxs Datei:
<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" />
....
Und dann das Javascript sah wie folgt aus:
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;
}
Vielleicht finden Sie das nützlich.
danke für deine Antwort cheeso. Gefunden eine einfache Lösung, überprüfen Sie bitte die Antworten ... – vinoth