I have a problem with taking MAC-addresses list in Windows XP from Inno Setup installer.
I'm trying to write some code (took it from Get MAC address in Inno Setup):
function GetMacAddressesList(out List: Array of String): Integer;
var
I: Integer;
WQLQuery: string;
WbemLocator: Variant;
WbemServices: Variant;
WbemObject: Variant;
WbemObjectSet: Variant;
begin
Result := 0;
WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('localhost', 'root\cimv2');
WQLQuery := 'Select * from Win32_NetworkAdapterConfiguration where IPEnabled=true';
WbemObjectSet := WbemServices.ExecQuery(WQLQuery);
if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
begin
Result := WbemObjectSet.Count;
SetArrayLength(List, WbemObjectSet.Count);
for I := 0 to WbemObjectSet.Count - 1 do
begin
WbemObject := WbemObjectSet.ItemIndex(I);
if not VarIsNull(WbemObject) then
begin
List[I] := WbemObject.MACAddress;
StringChange(List[i], ':', '');
StringChange(List[I], '-', '');
end;
end;
end;
end;
And I have a problem with ItemIndex
method. It appears only in Windows Vista. How can I do this on XP? I really don't know, because every solution, that I have found in Internet doesn't work. May be because in Inno Setup libraries there is no such type as IEnumVariant
and I can't iterate by SWbemObjectSet
with for each obj in objset
syntax...
I was also trying to get SWbemObject
with Item
method:
WbemObject := WbemObjectSet.Item('Win32_NetworkAdapterConfiguration.Index=' + IntToStr(I));
but it returns error
SWbemObjectSet: not found
Can anybody help me? Has this problem some solution?