【问题标题】:How to check for the existence of an IIS 7 web site via WiX 3.5?如何通过 WiX 3.5 检查是否存在 IIS 7 网站?
【发布时间】:2010-11-16 17:47:19
【问题描述】:

注意:这个问题也可以在WiX mailing list上找到。

我需要能够根据网站的描述检查是否存在 IIS7 网站。如果该网站不存在,我需要取消安装。如果该网站存在,我想继续安装。我还需要能够保存网站的站点 ID,以便在卸载过程中使用它。

出于调试目的,我对网站的描述进行了硬编码。我没有看到任何迹象表明正在 MSI 日志文件中检查网站。这是我正在使用的代码:

 <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>

使用 ORCA,我可以看到 IIsWebAddress 和 IIsWebSite 表已添加到 MSI。值是:

IIs网站

WEB:         IISWEBSITE
Description: Default Web Site
KeyAddress:  IisWebAddress
Id:          -1

IIsWebAddress

Address: IisWebAddress
Web_:    IISWEBSITE
Port:    1
Secure:  0

使用上面的代码,安装会停止并显示错误消息“未找到网站”。似乎 IISWEBSITE 永远不会被设置。不过,我知道存在“默认网站”。我知道我一定错过了什么,但是什么?

如何在 IIS 7 中简单检查网站是否存在?

【问题讨论】:

    标签: iis-7 web wix windows-installer wix3.5


    【解决方案1】:

    我也有同样的问题。

    我编写了一个自定义操作来检查注册表中的 IIS 版本。

    根据注册表值创建虚拟目录

    【讨论】:

      【解决方案2】:

      我用 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;
      }
      

      【讨论】:

        猜你喜欢
        • 2019-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-19
        • 2013-05-22
        • 1970-01-01
        • 1970-01-01
        • 2010-12-29
        相关资源
        最近更新 更多