Get network profile associated with a network adapter

168 Views Asked by At

I am looking for Windows network profiles associated with network adapters. I know there is the Windows API GetAdaptersAddresses() that gives adapter details, but it does not include the network profile associated with it.

1

There are 1 best solutions below

0
user3664223 On BEST ANSWER

I did not find exact answer but after searching msdn doc/ #include netlistmgr.h I can do in following way

if (SUCCEEDED(CoInitializeEx(NULL, COINITBASE_MULTITHREADED)))
{
    INetworkListManager* NetworkManager ;
    if (SUCCEEDED(CoCreateInstance(CLSID_NetworkListManager,
        NULL,
        CLSCTX_ALL,
        IID_INetworkListManager,
        (LPVOID*)&NetworkManager)))
    {
        IEnumNetworks** EnumNetworks;
        if (SUCCEEDED(pNetworkManager->GetNetworks(NLM_ENUM_NETWORK_CONNECTED, &EnumNetworks)))
        {
         while (true)
            {
                INetwork** Network;
                hr = EnumNetworks->Next(1, &pNetwork, &dwerr);
                if (hr == S_OK && dwerr > 0)
                {
                        Network->GetCategory(&Cat);
                        IEnumNetworkConnections** nwConnections ;
                        pNetwork->GetNetworkConnections(&nwConnections);
                        INetworkConnection** pNetworkConn;
                        while (true)
                        {
                            if (S_OK == nwConnections->Next(1, &pNetworkConn, &dwerr))
                            {
                                GUID aGUID;
                                NetworkConn->GetAdapterId(&aGUID);
                        }
                }
            }
        }
    }
}