Einzelnen Beitrag anzeigen

soulies

Registriert seit: 9. Dez 2005
234 Beiträge
 
#15

Re: Anzeigen der IPAdresse UND Name der Verbindung

  Alt 18. Jun 2008, 16:25
hoi,

Delphi-Quellcode:
function getWMIValue(WMI_CLASS:string;WMI_VALUE:string;Adapter:string): string;
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;
   i : integer ;
begin
   Result := '' ;
   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_WMIServices.execquery('Select * from '+wmiClass+' where caption like '+#39+#37+Adapter+#39,'WQL',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
        begin
          for i:=0 to VarArrayDimCount(l_WMIProperty.Get_Value) do
             result := result + l_WMIProperty.Get_Value[i] + ' ; ' ;
        end;
   end;
end;
und denn deine funktion

Delphi-Quellcode:
function GetIPAddress : string;

var
wmi : variant;
wmiService : variant;
nicstatus : variant;
card : Olevariant;
cnt : integer;
Enum: IEnumVariant;
P : IUnknown;
F : Cardinal;
cardCap : String;
strSettingID : String;


begin

  WMI:=CreateOleObject('WbemScripting.SWbemLocator');
  wmiService := wmi.ConnectServer('.', 'root\CIMV2');
  nicstatus := wmiService.InstancesOf('Win32_NetworkAdapterConfiguration');
  p := nicstatus._NewEnum;
  p.QueryInterface(IEnumVariant, Enum);
  for cnt := 0 to nicstatus.Count - 1 do
   begin
     Enum.Next(1, card, F);
     cardCap := Copy(card.Caption, 12, MaxInt);
     if cardCap = FAdapter then //Wenn Adapter in der jeweiligen Instanz gleich von mir definierter Adapter
        begin
          result := getWMIValue('Win32_NetworkAdapterConfiguration','IPAddress',FAdapter);
          break;
        end
   end;
   
end;

auf die schnelle zusammen gebastelt ...

cya
  Mit Zitat antworten Zitat