Disconnect Dialup Connection

Environment: ******-->

Problem:

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.

Solution:

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.

Needed:

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;
            break;
         }
      }
   }
   return bOk;
}




Comments

  • Error in RasEnumConnections

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

    Originally posted by: Adrian

    Hi,

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

    Regards
    Adrian

    Reply
  • Hangup before actual connection

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

    Originally posted by: Yefi

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

    Reply
  • 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.
    thanks
    babak

    Reply
  • 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

      Reply
    Reply
  • 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.

    Cheers

    A Madman

    Reply
  • 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.
    Tapas

    Reply
  • 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.
    Tapas

    Reply
  • 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.
    regards
    raju

    Reply
  • 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??

    Reply
  • 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,

    Oleg

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds