Inno安装程序:无法访问继承的OLE对象属性?

时间:2019-05-29 06:55:45

标签: wmi inno-setup ole pascalscript wbem

我按照这个question's接受的答案来查询机器的网络适配器。终于奏效了,但阅读这些属性的值仍然遇到问题:

  • Win32_NetworkAdapterConfiguration.Caption
  • Win32_NetworkAdapterConfiguration.Description

每次代码到达此行networkAdapter.Caption的行都会产生运行时错误,提示:

  

运行时错误(在60:8952):未知方法。

这是我的代码,是从上述堆栈溢出问题中采用的:

Log('Querying WMI for network adapter data...');
query := 'SELECT IPEnabled, IPAddress, MACAddress, InterfaceIndex FROM Win32_NetworkAdapterConfiguration';
networkAdapters := wbemServices.ExecQuery(query);
if not VarIsNull(networkAdapters) then
begin
  for i := 0 to networkAdapters.Count - 1 do
  begin
    networkAdapter := networkAdapters.ItemIndex(i);

    if (not VarIsNull(networkAdapter.MACAddress)) and networkAdapter.IPEnabled and (not VarIsNull(networkAdapter.IPAddress)) then
    begin
      SetArrayLength(sysInfo.networkAdapters, GetArrayLength(sysInfo.networkAdapters) + 1);

      nicRec := sysInfo.networkAdapters[adapterIndex];

      { Adapter name }
      nicRec.name := defaultIfNull(networkAdapter.Caption, Format('Adapter %d', [i]));
      Log(Format('    NIC[%d] name........: %s', [adapterIndex, nicRec.name]));
      { Adapter index }
      nicRec.index := defaultIfNull(networkAdapter.InterfaceIndex, adapterIndex);
      Log(Format('    NIC[%d] index.......: %d', [adapterIndex, nicRec.index]));
      { Adapter MAC address }
      nicRec.macAddress := defaultIfNull(networkAdapter.MACAddress, '');
      Log(Format('    NIC[%d] MAC address.: %s', [adapterIndex, nicRec.macAddress]));
      { Adapter ip address(es) }
      nicRec.ipAddresses := TStringList.Create;
      if not VarIsNull(networkAdapter.IPAddress) then
      begin
        ips := networkAdapter.IPAddress;
        for j := 0 to GetArrayLength(ips) - 1 do
        begin
          nicRec.ipAddresses.Add(ips[j]);
          Log(Format('    NIC[%d] IPv4 address: %s', [adapterIndex, nicRec.ipAddresses.Strings[j]]));          
        end;
      end;

      adapterIndex := adapterIndex + 1;
    end;
  end;
end;

在阅读Microsoft文档后,我遇到了这些属性的描述。它指出Win32_NetworkAdapterConfiguration类扩展了CIM_Setting类。此处定义了属性CaptionDescription。这是Inno Setup编译器的问题吗(我使用的是最新的6.0.2),还是我必须对may变量进行某种类型的转换?

1 个答案:

答案 0 :(得分:1)

当然可以访问继承的属性。实际上,Inno Setup甚至都不在乎那个类。它使用late binding。属性名称解析委托给类本身。

但是您没有使用Win32_NetworkAdapterConfigurationIWbemServices.ExecQuery返回IEnumWbemClassObject,而后者依次枚举IWbemClassObject。并且包含您的查询的结果。您的查询不要求提供CaptionDescription属性,因此结果集自然不包含它们。

将属性添加到查询中:

Query := 'SELECT IPEnabled, IPAddress, MACAddress, InterfaceIndex, Caption, Description FROM Win32_NetworkAdapterConfiguration';