我正在尝试使用 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
}
}
任何帮助,将不胜感激。谢谢你。