2010-03-10 54 views

回答

1

检查登记用于IIS ScriptMaps中的.svc扩展。要做到这一点,您可以使用WIX自定义操作中的WMI,这些操作以Javascript,VBScript或C/C++实现。这里是一个例子在Javascript中:

// IsWcf.js 
// ------------------------------------------------------------------ 
// 
// detect if WCF is installed; suitable for use within a WIX Custom Action. 
// 
// Copyright 2010, Cheeso. 
// 
// Licensed under the MS Public License 
// http://opensource.org/licenses/ms-pl.html 
// 
// To use this as a Custom Action in a WIX project, register it this way: 
// 
// <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
//  <Fragment> 
//  <Binary Id="B.JavaScript" SourceFile="CustomActions.js" /> 
//  <CustomAction Id="CA.DetectWcf" 
//      BinaryKey="B.JavaScript" 
//      JScriptCall="DetectWcf_CA" 
//      Execute="immediate" 
//      Return="check" /> 
//  </Fragment> 
// </Wix> 
// 
// And invoke it this way: 
// 
// <InstallUISequence> 
//  <Custom Action="CA.DetectWcf" After="CostFinalize" Overridable="yes">NOT Installed</Custom> 
// </InstallUISequence> 
// 
// 
// ======================================================= 


// http://msdn.microsoft.com/en-us/library/aa371254(VS.85).aspx 
var MsiActionStatus = { 
    None    : 0, 
    Ok    : 1, // success 
    Cancel   : 2, 
    Abort   : 3, 
    Retry   : 4, // aka suspend? 
    Ignore   : 5 // skip remaining actions; this is not an error. 
}; 

var MsgKind = { 
    Error   : 0x01000000, 
    Warning   : 0x02000000, 
    User    : 0x03000000, 
    Log    : 0x04000000 
}; 


// Format a number as hex. Quantities over 7ffffff will be displayed properly. 
function decimalToHexString(number) { 
    if (number < 0) 
     number = 0xFFFFFFFF + number + 1; 
    return number.toString(16).toUpperCase(); 
} 

function LogMessage(s) { 
    LogMessage2(s,MsgKind.Log); 
} 

function LogMessage2(s,kind){ 
    if (typeof Session !== "undefined") { 
     var record = Session.Installer.CreateRecord(0); 
     record.StringData(0) = "CustomActions: " + msg; 
     Session.Message(kind, record); 
    } 
    else { 
     WScript.echo(s); 
    } 
} 

function LogException(loc, exc) { 
    var s = "Exception {" + loc + "}: 0x" + decimalToHexString(exc.number) + " : " + exc.message; 
    if (typeof Session !== "undefined") { 
     var record = Session.Installer.CreateRecord(0); 
     record.StringData(0) = s; 
     Session.Message(MsgKind.Error + Icons.Critical + Buttons.btnOkOnly, record); 
    } 
    else { 
     LogMessage(s); 
    } 
} 

function stringEndsWith(subject, end) { 
    return (subject.match(end+"$") == end); 
} 

function DetectWcf_CA(website) { 
    try { 
     LogMessage("DetectWcf_CA() ENTER"); 

     if (website == null) { 
      website = "W3SVC"; // default value 
     } 

     LogMessage("website name(" + website + ")"); 

     var query = (website == "W3SVC") 
      ? "SELECT * FROM IIsWebServiceSetting" 
      : "SELECT * FROM IIsWebServerSetting WHERE Name = '" + website + "'"; 

     var iis = GetObject("winmgmts://localhost/root/MicrosoftIISv2"); 

     var settings = iis.ExecQuery(query); 
     LogMessage("WMI Query results : " + typeof settings); 

     if (settings == null) { 
      LogMessage("Cannot query IIS."); 
      return MsiActionStatus.Abort; 
     } 

     var item; 
     if (settings.Count != 0) { 
      for(var e = new Enumerator(settings); !e.atEnd(); e.moveNext()) { 
       item = e.item(); 
      } 
     } 

     var scriptMaps = item.ScriptMaps.toArray(); 
     var isSvcMapPresent = false; 
     var svcMapIndex = -1; 
     for (var i=0; i<scriptMaps.length; i++) { 
      var map = scriptMaps[i]; 
      for(var e = new Enumerator(map.Properties_); !e.atEnd(); e.moveNext()) { 
       item = e.item(); 
       if (item.Name == "Extensions" && item.Value == ".svc" && svcMapIndex == -1) { 
        svcMapIndex = i; 
       } 
       else if (i == svcMapIndex && item.Name == "ScriptProcessor" && stringEndsWith(item.Value,"aspnet_isapi.dll")) { 
        isSvcMapPresent = true; 
       } 
      } 
     } 

     LogMessage("DetectWcf_CA(): Is WCF Present?: " + isSvcMapPresent); 

     // works in WIX Custom Action only: 
     if (typeof Session !== "undefined") { 
      Session.Property("ISWCF")   = (isSvcMapPresent) ? "1" : "0"; 
     } 

     LogMessage("DetectWcf_CA() EXIT (Ok)"); 
    } 
    catch (exc1) { 
     LogException("DetectWcf_CA", exc1); 
     return MsiActionStatus.Abort; 
    } 
    return MsiActionStatus.Ok; 
} 


// actually run it, only if being invoked outside of WIX 
if (typeof Session == "undefined") { 
    DetectWcf_CA("W3SVC") ; 
}