RasEnumConnectionsA function

The RasEnumConnections function lists all active RAS connections. It returns each connection's handle and phone-book entry name.

Syntax

DWORD RasEnumConnectionsA(
  LPRASCONNA ,
  LPDWORD    ,
  LPDWORD    
);

Parameters

arg1

arg2

arg3

Return Value

If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is from Routing and Remote Access Error Codes or Winerror.h.

Return code Description
ERROR_BUFFER_TOO_SMALL
The lprasconn buffer is not large enough. The lpcbparameter is less than the dwSize member in the lprasconnparameter which is should be set prior to calling the function. The function returns the required buffer size in the variable pointed to by lpcb.

Remarks

If a connection was made without specifying a phone-book entry name, the information returned for that connection gives the connection phone number preceded by ".".

The following code sample code uses RasEnumConnections to enumerates the active RAS connections.

C++
#include <windows.h>
#include <stdio.h>
#include "ras.h"
#include "raserror.h"
#pragma comment(lib, "rasapi32.lib")

DWORD __cdecl wmain(){

DWORD dwCb = 0;
DWORD dwRet = ERROR_SUCCESS;
DWORD dwConnections = 0;
LPRASCONN lpRasConn = NULL;

// Call RasEnumConnections with lpRasConn = NULL. dwCb is returned with the required buffer size and 
// a return code of ERROR_BUFFER_TOO_SMALL
dwRet = RasEnumConnections(lpRasConn, &amp;dwCb, &amp;dwConnections);

if (dwRet == ERROR_BUFFER_TOO_SMALL){
    // Allocate the memory needed for the array of RAS structure(s).
    lpRasConn = (LPRASCONN) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb);
    if (lpRasConn == NULL){
        wprintf(L"HeapAlloc failed!\n");
        return 0;
    }
    // The first RASCONN structure in the array must contain the RASCONN structure size
    lpRasConn[0].dwSize = sizeof(RASCONN);
    
    // Call RasEnumConnections to enumerate active connections
    dwRet = RasEnumConnections(lpRasConn, &amp;dwCb, &amp;dwConnections);

    // If successful, print the names of the active connections.
    if (ERROR_SUCCESS == dwRet){
        wprintf(L"The following RAS connections are currently active:\n");
        for (DWORD i = 0; i &lt; dwConnections; i++){
                     wprintf(L"%s\n", lpRasConn[i].szEntryName);
              }
    }
    //Deallocate memory for the connection buffer
    HeapFree(GetProcessHeap(), 0, lpRasConn);
    lpRasConn = NULL;
    return 0;
}

// There was either a problem with RAS or there are no connections to enumerate    
if(dwConnections &gt;= 1){
    wprintf(L"The operation failed to acquire the buffer size.\n");
}else{
    wprintf(L"There are no active RAS connections.\n");
}

return 0;

}

RasEnumConnections cannot enumerate a connection as Active until RAS has successfully connected.

Windows Me/98/95:  RasEnumConnections enumerates a connection as Active as soon as it starts dialing.

  The most reliable way to enumerate and check for an active connection is to call <b>RasEnumConnections</b> or <a href="https://msdn.microsoft.com/579a9038-8216-4948-a065-fd45b97da73a">RasDial</a> to get a connection handle, then call <a href="https://msdn.microsoft.com/3b2a2f8d-b1ff-44d2-ba49-60877ca6c104">RasGetConnectStatus</a> to determine the actual connection state.

Requirements

   
Windows version Windows 2000 Professional [desktop apps only] Windows 2000 Server [desktop apps only]
Target Platform Windows
Header ras.h
Library Rasapi32.lib
DLL Rasapi32.dll

See Also

RASCONN

RasEnumEntries

RasGetConnectStatus

Remote Access Service (RAS) Overview

Remote Access Service Functions