Enumerate DUN Connections,
Connect to/Disconnect from the Internet

This sample shows how to enumerate your DUN (Dial-Up Networking) connections, connect to and disconnect from the internet programmatically.

Enumerating and starting a Dial-Up Networking internet connection.
Download Source Code

Developed By

This application was developed by Richard Wolf. You can reach Richard at rlw@completesoft.com.


The heart of this program is the WinInet class module which exposes methods to list DUN connections, start a DUN connection, and terminate a connection.

When the program starts an instance of the WinInet class is created and the ListDuns method called to enumerate the existing DUN connections and populate a listbox.

ListDuns relies on the RasEnumEntriesA function in Rasapi32.dll. RasEnumEntriesA populates an array of RAS_ENTRIES structures. This structure contains entries for the DUN connection's name and length.

To connect to the internet, Wininet's StartDUN method is used. StartDUN first checks the registry to see if a connection already exists. The registry value examined is the Remote Connection value under the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\RemoteAccess key.

If no connection is present, the InternetDial function from Wininet.dll is executed. One of the parameters to InternetDial is the Dial-Up Networking connection's name. InternetDial displays the standard dial up dialog, dials the associated phone number and attempts to connect.

After a connection is established the InternetHangUp function, again from Wininet.dll, is invoked to disconnect the DUN session from the internet.


Download this project and run it. Select a DUN connection to use and click the Connect button. Once you are connected to the internet, click the Check Connection button to verify your connection. Click Disconnect to terminate your connection.

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention "www.TheScarms.com"

Email this page

© Copyright 2024 TheScarms
Goto top of page