I use the following Delphi procedure GetAdapters
to list all enabled network adapters:
procedure GetAdapters;
var
oBindObj : IDispatch;
oNetAdapters, oNetAdapter,
odnsAddr, oWMIService : OleVariant;
i, iValue : LongWord;
oEnum : IEnumVariant;
oCtx : IBindCtx;
oMk : IMoniker;
sFileObj : WideString;
begin
MainForm.sComboBox1.Items.Clear;
sFileObj := 'winmgmts:\\.\root\cimv2';
OleCheck(CreateBindCtx(0,oCtx));
OleCheck(MkParseDisplayNameEx(oCtx, PWideChar(sFileObj), i, oMk));
OleCheck(oMk.BindToObject(oCtx, nil, IUnknown, oBindObj));
oWMIService := oBindObj;
oNetAdapters := oWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter=True AND MACAddress IS NOT NULL AND AdapterType IS NOT NULL');
oEnum := IUnknown(oNetAdapters._NewEnum) as IEnumVariant;
while oEnum.Next(1, oNetAdapter, iValue) = 0 do begin
try
MainForm.sCombobox1.Items.Add(oNetAdapter.Caption);
except
end;
oNetAdapter := Unassigned;
end;
odnsAddr := Unassigned;
oNetAdapters := Unassigned;
oWMIService := Unassigned;
end;
When I need to change my IP, I need to specify the network interface name, not the adapter name.
How can I list the network connection names like it is listed in Windows Network and Sharing Center.
Example:
Windows 7
Local Area Connection
Wireless Network Connection
Wireless Network Connection 1
Windows 10
Wifi
Wifi 2
etc..