Solved

Close Internet Connection

Posted on 2003-11-14
2
426 Views
Last Modified: 2008-02-01
Is there any api to close Internet connection in vb6? I tried to find it but unsuccessfully. I just want to click a button and then the program disconnects me from Internet. That's all.

this is all what I found:

Const Internet_Autodial_Force_Unattended As Long = 2
Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal dwReserved As Long) As Long

Private Sub Command1_Click()
Dim lResult As Long
lResult = InternetAutodialHangup(0&)
End Sub

but it didn't work. why? any other suggestions?
0
Comment
Question by:vbr666
2 Comments
 
LVL 1

Accepted Solution

by:
RocketMan801 earned 54 total points
ID: 9748789
if the conections is a dial-up connection u can hang up by calling the RasHangUp api, here is an example of how it works (took from the API guide, the KDP team), copy and paste in a form:


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

Const RAS_MAXENTRYNAME = 256
Const RAS_MAXDEVICETYPE = 16
Const RAS_MAXDEVICENAME = 128
Const RAS_RASCONNSIZE = 412
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 Sub Form_Load()
    Dim i As Long, lpRasConn(255) As RasConn, lpcb As Long
    Dim lpcConnections As Long, hRasConn As Long
   

    lpRasConn(0).dwSize = RAS_RASCONNSIZE
    lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
    lpcConnections = 0
   
    'Enumerate all the available connections
    returncode = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)

    If returncode = 0 Then
        For i = 0 To lpcConnections - 1
            hRasConn = lpRasConn(i).hRasConn
            'Hang up
            returncode = RasHangUp(ByVal hRasConn)
        Next i
    End If
End Sub
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9748805
Try using the example at the bottom of this page instead:

http://www.mentalis.org/apilist/RasHangUp.shtml
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help in WHSCRIPT 9 48
Adding to a VBA? 6 63
fso.FolderExists("\\server\HiddenFolder$") 4 52
Advice in Xamarin 21 57
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now