1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| function getSystemIPAddresses:Tstringlist;
var
l_WMILocator: ISWbemLocator; // Locator, gets Services
l_WMIServices: ISWbemServices; // Services, gets Object Definitions
l_WMIObjectDefinition: ISWbemObject; // Definition, gets Set of Objetcs
l_WMIObjectSet: SWbemObjectSet; // ObjectSet, gets Enum over Instances
l_WMIObjectInstances: IEnumVariant; // Enum of Instances, gets Object
l_WMIObject: ISWbemObject; // Object, gets Sets of his properties
l_WMIPropertySet: ISWbemPropertySet; // PropertySet, gets single property
l_WMIProperty: ISWbemProperty; // Property, gets Value
l_TempObj: OleVariant; // temporary used values
l_ObjValue: Cardinal;
sValue:string;
begin
// create the return object
result := TStringList.Create;
// retrieve object enum through WMI classes
l_WMILocator := CoSWbemLocator.Create;
l_WMIServices := L_WMILocator.ConnectServer('', 'root\cimv2', '', '', '', '',wbemConnectFlagUseMaxWait, nil);
l_WMIObjectDefinition := l_WMIServices.Get('Win32_NetworkAdapterConfiguration', wbemFlagUseAmendedQualifiers, nil);
l_WMIObjectSet := l_WMIObjectDefinition.Instances_(0, nil);
l_WMIObjectInstances := (l_WMIObjectSet._NewEnum) as IEnumVariant;
// iterate through enum values (WbemObjects) and get the property values
while (l_WMIObjectInstances.Next(1, l_TempObj, l_ObjValue) = S_OK) do
begin
l_WMIObject:= IUnknown(l_TempObj) as SWBemObject;
l_WMIPropertySet := l_WMIObject.Properties_;
l_WMIProperty := l_WMIPropertySet.Item('IPAddress', 0);
sValue:=conversion(l_WMIServices,l_WMIProperty);
if svalue<>'' then
begin
l_WMIProperty := l_WMIPropertySet.Item('IPAddress', 0);
sValue:=conversion(l_WMIServices,l_WMIProperty);
result.Append(sValue);
l_WMIProperty := l_WMIPropertySet.Item('IPSubnet', 0);
sValue:=conversion(l_WMIServices,l_WMIProperty);
result.Append(sValue);
l_WMIProperty := l_WMIPropertySet.Item('DefaultIPGateway', 0);
sValue:=conversion(l_WMIServices,l_WMIProperty);
result.Append(sValue);
end;
end;
end; |
Partager