Disconnect Dialup Connection

Environment: ******-->


Using the WinInet class there4s a slight problem when disconnecting from the Internet because shutting down der Internet session doesn4t close the dial up connection. Unfortunaltely CInternetSession::Close() wont give any possibility of getting the phone line free.


The RAS Api has got a method called RasHangUp() which does that job but it needs an RAS handle to do so. There a two ways to get hold of this handle; one is to establish the whole RAS session which is rather complicated and quite unnecessary. The easier one is shown in the code sample below. It uses RasEnumConnections() to get the desired handle; which also works if the connection wasn4t made using RAS directly.


In order to get the code below going it is necessary to

  1. have RAS installed on the system ( RASAPI32.DLL ). This is automatically the case when you`ve got a dial up network installed
  2. inlude RAS.H
  3. link RASAPI32.LIB

Source Code:

// Quit a dial up connection  - rasapi32.lib und #include "ras.h" needed
bool DisconnectRas()
   bool bOk = false;
   RASCONN ras[20];
   DWORD dSize,dNumber,dCount;

   ras[0].dwSize = sizeof(RASCONN);
   dSize = sizeof( ras );

   // Get active RAS - Connection
   if( RasEnumConnections( ras, &dSize, &dNumber ) == 0 )
      bOk = true;

      for( dCount = 0; dCount < dNumber; dCount++ )
         // Hang up that connection
         if( RasHangUp(ras[dCount].hrasconn) != 0 )
            bOk = false;
   return bOk;


  • Error in RasEnumConnections

    Posted by Legacy on 11/04/2002 12:00am

    Originally posted by: Adrian


    I tried the above functions and found that i have a return code of 610 ("BUFFER_INVALID") .. what exactly went wrong?


  • Hangup before actual connection

    Posted by Legacy on 05/09/2002 12:00am

    Originally posted by: Yefi

    Does anyone knows how to disconnect a call before the modem connection (while it rings). RasEnumConnections doesn't see the ringing modem.

  • Ras api

    Posted by Legacy on 05/04/2002 12:00am

    Originally posted by: babak

    hi every body
    anybody know about ras api in windows nt4
    for account user (dial out)time, byte resiv ,byte trans.
    and use multiport in a server.
    If everybody know plz send me email.

  • rasapi32.lib

    Posted by Legacy on 04/29/2002 12:00am

    Originally posted by: anis

    to disconnect dial up need link to rasapi32.lib. Simple question, how to link it?

    • rasapi32.lib ras.h raserror.h

      Posted by gemnath on 10/05/2004 05:27am

      I've almost the same problem. I am suching to download rasapi32.lib. To link it you need ras.h and raserror.h, but where can we find these files... I don't know. The same message in french : J'ai presque le mjme problhme. Je cherche ` tilicharger rasapi32.dll. Pour le linker on a besoin de ras.h et de raserror.h, mais oy trouver ces fichiers ?? Je ne sais pas. Nathanakl

  • Linking - The reality

    Posted by Legacy on 02/01/2002 12:00am

    Originally posted by: Charlie

    I'd just like to point out how frustrated I am with Visual C++. I am a VB developer, so admit upfront my ignorance with C++ and its internals. However, I do have some background in C++.

    That said, why is it that when I try and use the ras api, and I do a #include <ras.h> and link to rasapi32.lib for all configurations, that it appears not to link to the lib file??? Moreover, the code all worked last week - by adding the rasapi32.lib file to the link, but now just by starting vc++ and loading the previously working code, it now fails with "unrecognised identifier" on any mention of a RAS structure.

    I am incensed. Just how annoying is it when an IDE selects which day of the week it will compile on. Can anyone give me any pointers. There's a beer in it.


    A Madman

  • Method of dialup connection for UNIX O/S

    Posted by Legacy on 11/20/2001 12:00am

    Originally posted by: Tapas Choudhury

    RAS() is used for dialup connection ,which is compatible
    in WINDOWS O/S only.
    What is the equivalent methjod in "C" for dialup connection compatible for UNIX O/S.

    Seeking ur help.

  • Method of dialup connection for UNIX O/S

    Posted by Legacy on 11/20/2001 12:00am

    Originally posted by: Tapas Choudhury

    RAS() is used for dialup connection ,which is compatible
    in WINDOWS O/S only.
    What is the equivalent methjod in "C" for dialup connection compatible for UNIX O/S.

    Seeking ur help.

  • java dial up disconnect

    Posted by Legacy on 02/15/2001 12:00am

    Originally posted by: raju

    i want to disconnect dail up using java.
    please mail me soon.

  • Hooking the dialup dialog?

    Posted by Legacy on 01/25/2001 12:00am

    Originally posted by: Sionic

    I need to code a program that prevents the user from connecting to internet.... it should not even be possible to "ring"... anyone know how to hook the dialup dialog??

  • RasEnumConnections

    Posted by Legacy on 03/03/2000 12:00am

    Originally posted by: Oleg Vysotsky

    I have tried to use the proposed example to disconnect RAS connections under VC++ 6.0 but it doesn't work. Each time I got an error with code 610. This error is not described in ras.h.

    Could you please suggest what's the version of compiler should I use to resolve the problem?

    Thank you in advance.

    Best regards,


  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Complex hybrid environments can make it difficult to track interdependencies, increasing the risk of disrupting critical business services. In this white paper by EMA, you'll learn how application discovery and dependency mapping can help you: Meet granular targets for availability, cost, and time-to-revenue for cloud services. Accelerate mean time to repair (MTTR) while communicating better with stakeholders. Manage even the most complex hybrid environments more efficiently and effectively Understand the …

  • Rocket Mobile® for IBM i is an enterprise mobile application development and deployment platform for customers who rely on the IBM i system. Rocket Mobile for IBM i enables customers to leave proven applications in-place and rapidly repurpose them into new managed and secure mobile applications. Fast, easy creation of mobile, web, and hybrid mobile applications that deploy to any iOS, Android, or Windows mobile phone or tablet Built-in integration for seamless repurposing of existing IBM i applications …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date