我想在Windows上使用Delphi中的代码查找活动和连接网络的名称。可以有不止一个。
在此屏幕截图中,Windows 10显示了一个连接的NETGEAR21。 如果有人能回答这个问题,将不胜感激。
答案 0 :(得分:1)
我按照https://theroadtodelphi.com/2015/10/28/using-the-network-list-manager-nlm-api-from-delphi/中的描述首先创建了一个网络列表管理器界面。这将创建所需的文件NETWORKLIST_TLB.pas。 这是最小的实现:
unit ListTypes;
interface
uses
ActiveX,
NETWORKLIST_TLB,
ComObj;
function SetUpAndGetConnections: String;
function GetConnections: string;
implementation
uses
SysUtils,
Windows;
function SetUpAndGetConnections: String;
begin
CoInitialize(nil);
try
Result := GetConnections;
finally
CoUninitialize;
end;
end;
function GetConnections: String;
var
NetworkListManager: INetworkListManager;
EnumNetworkConnections: IEnumNetworkConnections;
NetworkConnection : INetworkConnection;
pceltFetched: ULONG;
begin
NetworkListManager := CoNetworkListManager.Create;
EnumNetworkConnections := NetworkListManager.GetNetworkConnections();
Result := '';
while true do
begin
EnumNetworkConnections.Next(1, NetworkConnection, pceltFetched);
if (pceltFetched>0) then
Result := Result + NetworkConnection.GetNetwork.GetName + #13#10
else
Break;
end;
end;
end.