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('Wbem Scripting. SWbemLocat or');
wmiService := wmi.ConnectServer('.', 'root\wmi');
nicstatus := wmiService.InstancesOf('MS Ndis_Media ConnectSta tus');
p := nicstatus._NewEnum;
p.QueryInterface(IEnumVari ant, Enum);
Cards:='';
for cnt := 0 to nicstatus.Count - 1 do
begin
Enum.Next(1, card, F);
connected := card.NdisMediaConnectStatu s;
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?
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('Wbem
wmiService := wmi.ConnectServer('.', 'root\wmi');
nicstatus := wmiService.InstancesOf('MS
p := nicstatus._NewEnum;
p.QueryInterface(IEnumVari
Cards:='';
for cnt := 0 to nicstatus.Count - 1 do
begin
Enum.Next(1, card, F);
connected := card.NdisMediaConnectStatu
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?
...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.
>>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_NetworkAdapterConfig uration colleciton and then iterate through the elements for the specific adapter.
or see this demo: http://www.ciuly.com/delphi/wmi/networkAdapterStatus/index.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_NetworkAdapterConfig
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.
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.
ziolko.
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_NetwordAdapterConfig uration
then select properties:
Description, IPAddress this will give you interface name and ip address
ziolko.
then select properties:
Description, IPAddress this will give you interface name and ip address
ziolko.
or combine results of Win32_NetwordAdapterConfig uration and Win32_NetwordAdapter
in Win32_NetworkAdapter NetConnectionStatus = 2 means connected
ziolko.
in Win32_NetworkAdapter NetConnectionStatus = 2 means connected
ziolko.
ASKER
Can you write all code how to get all Lan card names and ip addresses?
yup, you want with your method (WMI:=CreateOleObject('Wbe mScripting .SWbemLoca tor');) or can I do it my way?
ziolko.
ziolko.
ASKER
Yes i want with it.
ok, I'll post some code later today.
ziolko.
p.s. you still have old Qs opened
ziolko.
p.s. you still have old Qs opened
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
look at: Win32_NetworkAdapterConfig
ziolko.