// retrieve System MAC Addresses via WMI
//
const
// define used constants
WMI_LOCAL_COMPUTER = '
.';
WMI_SYSTEM_NAMESPACE = '
root\CIMV2';
WMI_CLASS_NIC = '
Win32_NetworkAdapter';
WMI_ATTRIB_MAC = '
MACAddress';
//function getSystemMACAddresses:String;
procedure getSystemMACAddresses(MAC: 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;
TmpMAC : TStringList;
begin
// create the return object
TmpMAC := TStringList.Create;
// retrieve object enum through WMI classes
l_WMILocator := CoSWbemLocator.Create;
l_WMIServices := L_WMILocator.ConnectServer(WMI_LOCAL_COMPUTER, WMI_SYSTEM_NAMESPACE, '
', '
', '
', '
', 0,
nil);
l_WMIObjectDefinition := l_WMIServices.Get(WMI_CLASS_NIC, 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(WMI_ATTRIB_MAC, 0);
if not VarIsNull(l_WMIProperty.Get_Value)
then
TmpMAC.Add(l_WMIProperty.Get_Value);
end;
TmpMAC.Sort;
MAC.Assign(TmpMAC);
TmpMAC.Free;
end;