我正在尝试使用WbemScripting.SWbemLocator对象枚举IIsWebServer的Properties_属性。我的目标是使用PascalScript代码来检索网站的服务器绑定。在VBScript中,我有以下代码:
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)?结束;
在JavaScript中,要获得ServerBindings,您必须输入类似于以下内容的内容:
var e = new Enumerator(nodeObj.Properties_);
for (; ! e.atEnd(); e.moveNext()) {
var prop = e.item();
if (prop.Name == 'ServerBindings') {
// Do something
}
}任何帮助都将不胜感激。谢谢。
发布于 2012-12-21 16:21:22
不幸的是,Inno代码不支持本机执行COM枚举,但您可以通过使用助手DLL来获得支持。详情请参见here。
但是,如果您只想访问一个已知的命名属性,那么就这么做吧。
nodeObj.ServerBindingshttps://stackoverflow.com/questions/13976912
复制相似问题