Link to home
Start Free TrialLog in
Avatar of selas
selas

asked on

Get All Lan card names with ip address DELPHI

Hello,

i am using WMI class to get computer hardware information. My procedure is bellow:

procedure TfmMain.ShowNetworkStatus;
var
 wmi : variant;
 wmiService : variant;
 nicstatus : variant;
 card : Olevariant;
 cnt : integer;
 Enum: IEnumVariant;
 P : IUnknown;
 F : Cardinal;
 connected : integer;
 status : string;
begin
  ShowMessage('card lans searching...');
  WMI:=CreateOleObject('WbemScripting.SWbemLocator');
  wmiService := wmi.ConnectServer('.', 'root\wmi');
  nicstatus := wmiService.InstancesOf('MSNdis_MediaConnectStatus');
  p := nicstatus._NewEnum;
  p.QueryInterface(IEnumVariant, Enum);

  Cards:='';
  for cnt := 0 to nicstatus.Count - 1 do
   begin
     Enum.Next(1, card, F);
     connected := card.NdisMediaConnectStatus;
     if (connected = 0) then
       Status := 'connected'
        else
         Status := 'network cable unplugged';
     Cards := Cards + (card.InstanceName + ' : ' + Status) + #13#10;
   end;
end;


Please, can you tell me how to add computer ip address and card instance name and card status?
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

MSNdis_MediaConnectStatus class does not contain any methods do add new class instances, so it's impossible to do what you want

look at: Win32_NetworkAdapterConfiguration in root\cimv2 namespace you could use EnableStatic method to set static IP address on selected interface but i'm afraid you can't add new one

ziolko.
...or maybe I misunterstood you,
>>Please, can you tell me how to add computer ip address and card instance name and card status?
you want add those information to your result so you can display it or you want add new interface to computer configuration?

ziolko.
see this PAQ: https://www.experts-exchange.com/questions/21237093/Detect-network-connection-state-changes-using-SENS-or-other-method.html

it doesn't use WMI but winapi. I use it in a product and it behaves ok.

if you want WMI, I think you'll need to get the Win32_NetworkAdapterConfiguration colleciton and then iterate through the elements for the specific adapter.

or see this demo: http://www.ciuly.com/delphi/wmi/networkAdapterStatus/index.html
also look at:http://adremsoft.com/demo/download.php
download ITools2007 it contains WMI Tools with very nice WMI browser which will help you find WMI class which contains information you need

ziolko.
btw. you have some open Qs some of them pretty old

ziolko.
Avatar of selas
selas

ASKER

i want to show all lan cards names with ip address and lan cards status. Can you show procedure how to do it?
you'll have to combine results of MSNdis_MediaConnectStatus (the one you already have) then connect to root\cimv2 namespace and use Win32_NetwordAdapterConfiguration
then select properties:
Description, IPAddress this will give you interface name and ip address

ziolko.
or combine results of Win32_NetwordAdapterConfiguration and Win32_NetwordAdapter
in Win32_NetworkAdapter NetConnectionStatus = 2 means connected

ziolko.
Avatar of selas

ASKER

Can you write all code how to get all Lan card names and ip addresses?
yup, you want with your method (WMI:=CreateOleObject('WbemScripting.SWbemLocator');) or can I do it my way?

ziolko.
Avatar of selas

ASKER

Yes i want with it.
ok, I'll post some code later today.

ziolko.

p.s. you still have old Qs opened
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial