Community discussion forum

Disconnect from the Internet

This is a comment thread discussing Disconnect from the Internet
  • 9 years ago

    This thread is for discussions of Disconnect from the Internet.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 years ago

    It cannot work for me. I cannot disconnect my internet connection.

  • 6 years ago

    No offence to the kool Mr Crowley but tuhsan has written a Tutorial which you may be interested in:


    http://www.developerfusion.com/show/1920/3/ [Connecting/Disconnecting]


    http://www.developerfusion.com/show/1920/ [Using the WinInet API - Part I]


    I've found its easier and smaller code than Jame's!


    Happy [dis]connecting!

  • 4 years ago

    Aside from ERRORSUCCESS not being defined (const ERRORSUCCESS = 0), this code was exactly what I was after, and it allows me to extract information about active connections that I didn't think could be extracted.


    Thanks for posting it.

  • 4 years ago

    First thanks for your code.
    I'm in trouple with this proplem - API RASConnections.
    You know, your code write in Vb6 and a convert it into VB.Net but the result not perfect, when I debug I realize the return of Error code is 87, and I don't know while - I found it in file RasError.h, but I could find anything about this Error code?? Pls help me !!!
    Here is my code in VB.Net


       'Module Code
       Public Structure RasEntryName
           Dim dwSize As Long
           Dim szEntryName() As Byte


           Public Sub init()
               ReDim szEntryName(RAS_MaxEntryName)
           End Sub
       End Structure


       Public Structure RasConn
           Dim dwSize As Long
           Dim hRasConn As Long
           Dim szEntryName() As Byte
           Dim szDeviceType() As Byte
           Dim szDeviceName() As Byte


           Public Sub init()
               ReDim szEntryName(RASMaxEntryName)
               ReDim szDeviceType(RAS
    MaxDeviceType)
               ReDim szDeviceName(RAS_MaxDeviceName)
           End Sub
       End Structure


       Public Declare Function RasEnumConnections Lib _
       "rasapi32.dll" Alias "RasEnumConnectionsA" (ByVal lpRasConn As _
       RasConn, ByVal lpcb As Long, ByVal lpcConnections As Long) As Long


       Public Declare Function RasHangUp Lib "rasapi32.dll" Alias _
       "RasHangUpA" (ByVal hRasConn As Long) As Long
       Public gstrISPName As String
       Public ReturnCode As Long


       Public Sub HangUp()
           Dim i As Long
           Dim lpRasConn(255) As RasConn
           For i = 0 To 255
               lpRasConn(i).init()
           Next
           i = 0
           Dim lpcb As Long
           Dim lpcConnections As Long
           Dim hRasConn As Long
           lpRasConn(0).dwSize = RASRASCONNSIZE
           lpcb = RAS
    MaxEntryName * lpRasConn(0).dwSize
           lpcConnections = 0
           ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, _
           lpcConnections)


           If ReturnCode = ERROR_SUCCESS Then
               For i = 0 To lpcConnections - 1
                   If Trim(ByteToString(lpRasConn(i).szEntryName)) = Trim(gstrISPName) Then
                       hRasConn = lpRasConn(i).hRasConn
                       ReturnCode = RasHangUp(hRasConn)
                   End If
               Next i
           End If
       End Sub


       Public Function ByteToString(ByVal bytString() As Byte) As String
           Dim i As Integer
           ByteToString = ""
           i = 0
           While bytString(i) = 0&
               ByteToString = ByteToString & Chr(bytString(i))
               i = i + 1
           End While
       End Function


       Public Sub getConnections()
           Call HangUp()
       End Sub

  • 3 years ago

    I got the same problem, anybody can help ?

  • 3 years ago

    I am getting the same problem , Please Help.. Did  anyone found a solution yet

Post a reply

Enter your message below

Sign in or Join us (it's free).