Click here to Skip to main content
13,086,264 members (89,709 online)
Click here to Skip to main content
Add your own
alternative version


40 bookmarked
Posted 8 Apr 2013

Using Network List Manager (C++)

Rate this:
Please Sign up or sign in to vote.
This article explains how to use Network List Manager service to identify and retrieve properties of each network that PC Connects to.


The sample application enumerates the networks to which the PC is connected and show some of the properties of the network selected. It also listens for the connection status and updates if connection changed.


Network List Manager runs as a service in the context of Svchost.exe and is started during the computer boot procedure. The Network List Manager service maintains a table of available networks and network attributes that are retrieved by applications through the Network List Manager API.  INetworkListManager is the interface we are using to communicate with the Network List Manager Service for Querying the Network details.

Note: INetworkListManager is introduced in Windows Vista.  

Using the code  

The sample Application is developed as an MFC dialog app, using Visual Studio 2012.  INetworkListManager is implemented on the CLSID_NetworkListManager CoClass. In order to use this interface, it is necessary to create the CLSID_NetworkListManager COM object as shown below. Ensure you have called CoInitialize() before making these calls.

CComPtr <INetworkListManager> m_pNLM;

Once you created the CLSID_NetworkListManager object, you can enumerate all connected networks as shown below. 

CComPtr<IEnumNetworks> pEnumNetworks;
if(SUCCEEDED(m_pNLM->GetNetworks(NLM_ENUM_NETWORK_CONNECTED, &pEnumNetworks)))
    DWORD dwReturn = 0;
       CComPtr<INetwork> pNetwork;
       hr = pEnumNetworks->Next(1, &pNetwork, &dwReturn);
       if(hr == S_OK && dwReturn > 0)

The INetwork interface represents a network on the local machine. It can also represent a collection of network connections with a similar network signature. You can get the Category, Connectivity types, Description, Domain Type and Name of the network using the GET methods of INetwork interface. Dump_NW_Info in the sample collects all these information. The INetwork interface has a property called get_IsConnectedToInternet, which specifies if the network has internet connectivity. 

Listening for Connection Events 

INetworkListManagerEvents is a message sink interface that a client implements to get overall machine state related events. Applications that are interested on higher-level events, for example internet connectivity, implement this interface.  This interface inherits from IUnknown interface and has one method.  


We implemented our Sink class as follows:

class CoNetworkEventHandler : public INetworkListManagerEvents
    virtual ~CoNetworkEventHandler(void);
    STDMETHODIMP QueryInterface (REFIID riid, void** pIFace);
    STDMETHODIMP ConnectivityChanged(NLM_CONNECTIVITY NewConnectivity);
    long m_lRefCnt;
    DWORD m_dwCookie;

After creating the Sink Object we can establish a connection to the connection point as follows:

CoNetworkEventHandler * m_pSink;
LPUNKNOWN m_pUnkSink; 
m_pSink = new CoNetworkEventHandler(); 
if (SUCCEEDED (m_pSink->QueryInterface(IID_IUnknown, (void**) &m_pUnkSink)))
    AfxConnectionAdvise (m_pNLM, __uuidof(INetworkListManagerEvents),
                             m_pUnkSink, FALSE, &m_dwCookie); 

Once a network event occurs this call back function will get called. 

HRESULT CoNetworkEventHandler::ConnectivityChanged( NLM_CONNECTIVITY NewConnectivity)
    bool bInternet = false;
    if((NewConnectivity & NLM_CONNECTIVITY_IPV4_INTERNET) || 
       (NewConnectivity & NLM_CONNECTIVITY_IPV4_INTERNET))
        bInternet = true;
    PostMessage(AfxGetApp()->GetMainWnd()->m_hWnd, UM_NETWORK_NOTIFY, 
                (WPARAM) bInternet, 0);
    return S_OK;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jithesh Chandrasekharan
Technical Lead
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionRunning this in console App Pin
Avinash Pachar27-Sep-16 1:49
memberAvinash Pachar27-Sep-16 1:49 
QuestionConcern with Virtual Private Network Pin
DebajyotiSahu14-May-14 18:02
memberDebajyotiSahu14-May-14 18:02 
QuestionGood one! Pin
Rejeesh.T.S16-Feb-14 23:48
memberRejeesh.T.S16-Feb-14 23:48 
QuestionThanks Pin
marc ochsenmeier9-Dec-13 21:38
membermarc ochsenmeier9-Dec-13 21:38 
QuestionFailed to include <Afxwin.h> Pin
HamidYaseen9-Apr-13 3:06
memberHamidYaseen9-Apr-13 3:06 
AnswerRe: Failed to include <Afxwin.h> Pin
Jithesh Chandrasekharan9-Apr-13 3:19
memberJithesh Chandrasekharan9-Apr-13 3:19 
QuestionWIFI Connection Pin
fmaeseel9-Apr-13 1:09
memberfmaeseel9-Apr-13 1:09 
AnswerRe: WIFI Connection Pin
Jithesh Chandrasekharan9-Apr-13 7:19
memberJithesh Chandrasekharan9-Apr-13 7:19 
GeneralMy vote of 4 Pin
Sanjay K. Gupta9-Apr-13 0:23
professionalSanjay K. Gupta9-Apr-13 0:23 
QuestionVC6 project ? Pin
Flaviu28-Apr-13 20:17
memberFlaviu28-Apr-13 20:17 
AnswerRe: VC6 project ? Pin
Jithesh Chandrasekharan9-Apr-13 3:23
memberJithesh Chandrasekharan9-Apr-13 3:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 8 Apr 2013
Article Copyright 2013 by Jithesh Chandrasekharan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid