Iterate SWbemObjectSet in Windows XP and Inno Setup

被刻印的时光 ゝ 提交于 2019-12-01 11:32:52

Yes, you would have to implement the IEnumVariant. Not sure if that's possible with Pascal Script.


Use of the SWbemObjectSet.Item method is like this:

WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('localhost', 'root\cimv2');

WQLQuery := 'Select * from Win32_NetworkAdapterConfiguration';
WbemObjectSet := WbemServices.ExecQuery(WQLQuery);
if not VarIsNull(WbemObjectSet) then
begin
  for I := 0 to WbemObjectSet.Count - 1 do
  begin
    WbemObject := WbemObjectSet.Item(Format('Win32_NetworkAdapterConfiguration=%d', [I]));
    if WbemObject.IPEnabled then
    begin
      Log(WbemObject.MACAddress);
    end;
  end;
end;

But it seems that neither this approach works on Windows XP.


A possible workaround is to execute

wmic nicconfig get MACAddress 

redirect to a file and read it.

See How to get an output of an Exec'ed program in Inno Setup?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!