Solved

Disconnecting Dial Up Network

Posted on 1998-08-04
2
156 Views
Last Modified: 2010-05-03
How can I disconnecting an internet connection WITHOUT running DUN and send key?
0
Comment
Question by:fury
2 Comments
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1467770
' *** disconnect from the internet using VB
Private Const RAS_MAXENTRYNAME As Integer = 256
Private Const RAS_MAXDEVICETYPE As Integer = 16
Private Const RAS_MAXDEVICENAME As Integer = 128
Private Const RAS_RASCONNSIZE As Integer = 412

Private Type RasEntryName
    dwSize                          As Long
    szEntryName(RAS_MAXENTRYNAME)   As Byte
End Type

Private Type RasConn
    dwSize                          As Long
    hRasConn                        As Long
    szEntryName(RAS_MAXENTRYNAME)   As Byte
    szDeviceType(RAS_MAXDEVICETYPE) As Byte
    szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type

Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Function RASHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long

Public Sub HangUpConnection(sISPName As String)
   ' *** Disconnect from the internet using VB?
   ' *** If you want to terminate all connections to the internet using Visual Basic,
   ' *** you can use the Remote Access Services Hangup function.
   
   Dim i                As Long
   Dim lpRasConn(255)   As RasConn
   Dim lpcb             As Long
   Dim lpcConnections   As Long
   Dim hRasConn         As Long
   Dim nRet             As Long
   
   lpRasConn(0).dwSize = RAS_RASCONNSIZE
   lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
   lpcConnections = 0
   nRet = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
   
   If nRet = ERROR_SUCCESS Then
      For i = 0 To lpcConnections - 1
         If Trim(ByteToString(lpRasConn(i).szEntryName)) = Trim(sISPName) Then
            hRasConn = lpRasConn(i).hRasConn
            nRet = RASHangUp(ByVal hRasConn)
         End If
      Next
   End If

End Sub

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

0
 

Author Comment

by:fury
ID: 1467771
well..I know I am greedy :) Can I also have the code for the SENDKEY way....
Thanks a lot

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now