Solved

Disconnecting Dial Up Network

Posted on 1998-08-04
2
161 Views
Last Modified: 2010-05-03
How can I disconnecting an internet connection WITHOUT running DUN and send key?
0
Comment
Question by:fury
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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