unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WbemScripting_TLB,
ActiveX, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
var
l_Values: TStringList;
implementation
{$R *.dfm}
function getWMIValue(WMI_CLASS:
string;WMI_VALUE:
string): TStringList;
var
l_WMILocator: ISWbemLocator;
l_WMIServices: ISWbemServices;
l_WMIObjectDefinition: ISWbemObject;
l_WMIObjectSet: SWbemObjectSet;
l_WMIObjectInstances: IEnumVariant;
l_WMIObject: ISWbemObject;
l_WMIPropertySet: ISWbemPropertySet;
l_WMIProperty: ISWbemProperty;
l_TempObj: OleVariant;
l_ObjValue: Cardinal;
begin
result := TStringList.Create;
l_WMILocator := CoSWbemLocator.Create;
l_WMIServices := L_WMILocator.ConnectServer('
.', '
root\CIMV2', '
', '
', '
', '
', 0,
nil);
l_WMIObjectDefinition := l_WMIServices.Get(WMI_CLASS, wbemFlagUseAmendedQualifiers,
nil);
l_WMIObjectSet := l_WMIObjectDefinition.Instances_(0,
nil);
l_WMIObjectInstances := (l_WMIObjectSet._NewEnum)
as IEnumVariant;
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_VALUE, 0);
if not VarIsNull(l_WMIProperty.Get_Value)
then
result.Add(l_WMIProperty.Get_Value)
else result.Add('
<unbekannt>');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var x:integer;
begin
l_Values := getWMIValue('
Win32_NetworkAdapterConfiguration','
IPAddress');
for x:=0
to l_Values.Count-1
do begin
ShowMessage(l_Values.Strings[x]);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var x:integer;
begin
l_Values := getWMIValue('
Win32_NetworkAdapter','
Name');
for x:=0
to l_Values.Count-1
do begin
ShowMessage(l_Values.Strings[x]);
end;
end;
end.