2012-12-20 192 views
1

我想枚舉使用WbemScripting.SWbemLocator對象的IIsWebServer的Properties_屬性。我的目標是使用PascalScript代碼來檢索網站的服務器綁定。在VBScript中,我有以下代碼:Inno setup枚舉器

Dim site, binding, url 
Set site = GetObject("IIS://localhost/W3SVC/1") 
For Each binding In site.ServerBindings 
    url = binding 
    Exit For 
Next 
If Left(url, 1) = ":" Then 
    url = "localhost" & url 
End If 
If Right(url, 1) Then 
    url = Left(url, Len(url) - 1) 
End If 
Set site = Nothing 

我寫了這個代碼寫意所以它可能不準確,但我想這樣做在PascalScript以類似的方式。我堅持的部分是通過ServerBindings枚舉。我已經嘗試了很多事情來實現它的功能,並且在當前時刻,我擁有以下PascalScript:

function GetWebSites() : Array of String; 
var 
    locatorObj, providerObj, nodeObj, appRoot: Variant; 
    props : String; 
begin 
    locatorObj := CreateOleObject('WbemScripting.SWbemLocator'); 
    providerObj := locatorObj.ConnectServer(GetComputerNameString(), 'root/MicrosoftIISv2'); 
    nodeObj := providerObj.Get('IIsWebServer=''W3SVC/1'''); 

    props := nodeObj.Properties_; 
    // How do I enumerate through the properties here? Or, my actual goal is from this point how do I get the ServerBindings (or the first element in the ServerBindings array)? 

end;

在JavaScript中,得到ServerBindings,你必須我們類似如下的內容:

var e = new Enumerator(nodeObj.Properties_); 
for (; ! e.atEnd(); e.moveNext()) { 
    var prop = e.item(); 
    if (prop.Name == 'ServerBindings') { 
     // Do something 
    } 
} 

任何幫助,將不勝感激。謝謝。

回答

1

Inno代碼不幸地不支持原生地執行COM枚舉,但是您可以通過使用助手DLL來獲得支持。有關詳細信息,請參閱here

如果你只是想訪問一個已知的命名屬性,但 - 只是這樣做。

nodeObj.ServerBindings