Iis 7 如何通过WiX 3.5检查IIS 7网站的存在?
注意:此问题也可以在上找到 我需要能够根据网站的描述检查IIS7网站的存在。如果该网站不存在,我需要取消安装。如果该网站存在,我想继续安装。我还需要能够保存网站的网站id,以便我可以在卸载期间使用它 为了调试的目的,我硬编码了网站的描述。我没有看到任何迹象表明正在MSI日志文件中对网站进行检查。这是我正在使用的代码:Iis 7 如何通过WiX 3.5检查IIS 7网站的存在?,iis-7,web,wix,windows-installer,wix3.5,Iis 7,Web,Wix,Windows Installer,Wix3.5,注意:此问题也可以在上找到 我需要能够根据网站的描述检查IIS7网站的存在。如果该网站不存在,我需要取消安装。如果该网站存在,我想继续安装。我还需要能够保存网站的网站id,以便我可以在卸载期间使用它 为了调试的目的,我硬编码了网站的描述。我没有看到任何迹象表明正在MSI日志文件中对网站进行检查。这是我正在使用的代码: <iis:WebSite Id="IISWEBSITE" Description="Default Web Site" SiteId="*"> <i
<iis:WebSite Id="IISWEBSITE" Description="Default Web Site" SiteId="*">
<iis:WebAddress Id="IisWebAddress" Port="1"/>
</iis:WebSite>
<Condition Message="Website [IISWEBSITE] not found.">
<![CDATA[IISWEBSITE]]>
</Condition>
IIsWebAddress
Address: IisWebAddress
Web_: IISWEBSITE
Port: 1
Secure: 0
使用上述代码,安装将停止,并显示错误消息“未找到网站”。似乎IISWEBSITE从未设置过。不过,我知道“默认网站”是存在的。我知道我一定错过了什么,但是什么
如何简单地检查IIS 7中是否存在网站?我也有同样的问题 我编写了一个自定义操作来检查注册表中IIS的版本
基于注册表值创建虚拟目录我用Javascript编写了一个自定义操作来实现这一点。如果您假设IIS7,那么您可以使用appcmd.exe工具,只需从Javascript中调用它即可获得站点列表。理论上,这很简单。但在实践中,你需要跳出一大堆障碍 以下是我的想法:
function RunAppCmd(command, deleteOutput) {
var shell = new ActiveXObject("WScript.Shell"),
fso = new ActiveXObject("Scripting.FileSystemObject"),
tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder),
tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName()),
windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder),
appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " " + command,
rc;
deleteOutput = deleteOutput || false;
LogMessage("shell.Run("+appcmd+")");
// use cmd.exe to redirect the output
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+ .
//
// The return value is an array of JS objects, one per site.
//
function GetWebSites_Appcmd() {
var r, fso, textStream, sites, oneLine, record,
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
props = tokens[2].slice(1,-1),
t2 = props.match(/\w+:.+?(?=,\w+:|$)/g),
bindingsString = t2[1],
ix1 = bindingsString.indexOf(':'),
t3 = bindingsString.substring(ix1+1).split(','),
L1 = t3.length,
bindings = {}, i, split, obj, p2;
for (i=0; i<L1; i++) {
split = t3[i].split('/');
obj = {};
if (split[0] == "net.tcp") {
p2 = split[1].split(':');
obj.port = p2[0];
}
else if (split[0] == "net.pipe") {
p2 = split[1].split(':');
obj.other = p2[0];
}
else if (split[0] == "http") {
p2 = split[1].split(':');
obj.ip = p2[0];
if (p2[1]) {
obj.port = p2[1];
}
obj.hostname = "";
}
else {
p2 = split[1].split(':');
obj.hostname = p2[0];
if (p2[1]) {
obj.port = p2[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");
r = RunAppCmd("list sites");
if (r.rc !== 0) {
// 0x80004005 == E_FAIL
throw new Exception("ApplicationException", "exec appcmd.exe returned nonzero rc ("+r.rc+")", 0x80004005);
}
fso = new ActiveXObject("Scripting.FileSystemObject");
textStream = fso.OpenTextFile(r.outputfile, OpenMode.ForReading);
sites = [];
// Read from the file and parse the results.
while (!textStream.AtEndOfStream) {
oneLine = textStream.ReadLine();
record = ParseOneLine(oneLine);
LogMessage(" site: " + record.name);
sites.push(record);
}
textStream.Close();
fso.DeleteFile(r.outputfile);
LogMessage("GetWebSites_Appcmd() EXIT");
return sites;
}
函数RunAppCmd(命令,deleteOutput){
var shell=新的ActiveXObject(“WScript.shell”),
fso=新的ActiveXObject(“Scripting.FileSystemObject”),
tmpdir=fso.getSpecialFolders(SpecialFolders.TemporaryFolder),
tmpFileName=fso.BuildPath(tmpdir,fso.GetTempName()),
windir=fso.getSpecialFolders(SpecialFolders.WindowsFolder),
appcmd=fso.BuildPath(windir,“system32\\inetsrv\\appcmd.exe”)+“”+命令,
rc;
deleteOutput=deleteOutput | | false;
日志消息(“shell.Run(“+appcmd+”);
//使用cmd.exe重定向输出
rc=shell.Run(“%comspec%/c”+appcmd+“>”+tmpFileName,WindowStyle.Hidden,true);
日志消息(“shell.Run rc=“+rc”);
如果(删除输出){
fso.DeleteFile(tmpFileName);
}
返回{
rc:rc,
outputfile:(deleteOutput)?null:tmpFileName
};
}
//GetWebSites_Appcmd()
//
//仅在IIS7+上使用Appcmd.exe获取网站信息。
//
//返回值是一个JS对象数组,每个站点一个。
//
函数GetWebSites\u Appcmd(){
变量r、fso、文本流、站点、单行、记录、,
ParseOneLine=函数(oneLine){
//拆分字符串:捕获带引号的字符串或包围的字符串
//由帕伦斯,或最后,由空格分隔的标记,
var tokens=oneLine.match(/“[^”]+“|\(.+\)|[^]+/g),
//拆分第三个字符串:它是一组由冒号分隔的属性
道具=令牌[2]。切片(1,-1),
t2=道具匹配(/\w+:.+?(?=,\w+:|$)/g),
bindingsString=t2[1],
ix1=bindingsString.indexOf(“:”),
t3=bindingsString.substring(ix1+1).split(','),
L1=t3.5米长,
绑定={},i,split,obj,p2;
对于(i=0;i
function RunAppCmd(command, deleteOutput) {
var shell = new ActiveXObject("WScript.Shell"),
fso = new ActiveXObject("Scripting.FileSystemObject"),
tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder),
tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName()),
windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder),
appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " " + command,
rc;
deleteOutput = deleteOutput || false;
LogMessage("shell.Run("+appcmd+")");
// use cmd.exe to redirect the output
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+ .
//
// The return value is an array of JS objects, one per site.
//
function GetWebSites_Appcmd() {
var r, fso, textStream, sites, oneLine, record,
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
props = tokens[2].slice(1,-1),
t2 = props.match(/\w+:.+?(?=,\w+:|$)/g),
bindingsString = t2[1],
ix1 = bindingsString.indexOf(':'),
t3 = bindingsString.substring(ix1+1).split(','),
L1 = t3.length,
bindings = {}, i, split, obj, p2;
for (i=0; i<L1; i++) {
split = t3[i].split('/');
obj = {};
if (split[0] == "net.tcp") {
p2 = split[1].split(':');
obj.port = p2[0];
}
else if (split[0] == "net.pipe") {
p2 = split[1].split(':');
obj.other = p2[0];
}
else if (split[0] == "http") {
p2 = split[1].split(':');
obj.ip = p2[0];
if (p2[1]) {
obj.port = p2[1];
}
obj.hostname = "";
}
else {
p2 = split[1].split(':');
obj.hostname = p2[0];
if (p2[1]) {
obj.port = p2[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");
r = RunAppCmd("list sites");
if (r.rc !== 0) {
// 0x80004005 == E_FAIL
throw new Exception("ApplicationException", "exec appcmd.exe returned nonzero rc ("+r.rc+")", 0x80004005);
}
fso = new ActiveXObject("Scripting.FileSystemObject");
textStream = fso.OpenTextFile(r.outputfile, OpenMode.ForReading);
sites = [];
// Read from the file and parse the results.
while (!textStream.AtEndOfStream) {
oneLine = textStream.ReadLine();
record = ParseOneLine(oneLine);
LogMessage(" site: " + record.name);
sites.push(record);
}
textStream.Close();
fso.DeleteFile(r.outputfile);
LogMessage("GetWebSites_Appcmd() EXIT");
return sites;
}