![]() |
MAC Adresse(n) des Rechners via WMI ermitteln
Mit dem folgenden Code kann man die MAC - Adressen aller Interfaces via WMI ermitteln.
Delphi-Quellcode:
interface
uses // Delphi VCL Units Classes; // external forward declarations function getSystemMACAddresses: TStringList; implementation uses // Delphi VCL Units Windows, Dialogs, ComObj, ActiveX, // Imported type libraries WbemScripting_TLB; { Typelib name: "Microsoft Windows WMI Scripting V1.2 Library" } const // define used constants WMI_LOCAL_COMPUTER = '.'; WMI_SYSTEM_NAMESPACE = 'root\CIMV2'; WMI_CLASS_NIC = 'Win32_NetworkAdapter'; WMI_ATTRIB_MAC = 'MACAddress'; // retrieve System MAC Addresses via WMI // function getSystemMACAddresses: 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; begin // create the return object result := 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 result.Add(l_WMIProperty.Get_Value); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz