• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Connect/Disconnect From Internet

I need a working code example that will sense when a computer is logged onto the Internet and then have my program Disconnect the Connection. If this is possible, will it work on windows95 and windows98 and if not what is the difference ?
Tubesoxx
0
tubesoxx
Asked:
tubesoxx
1 Solution
 
JuiletteCommented:
''''terminate all connections of internet'''''''''''''''''''''''''
'
'''''''''''put the following code in a bas module'''''''''''''''''
'
Public Const RAS_MAXENTRYNAME As Integer = 256
Public Const RAS_MAXDEVICETYPE As Integer = 16
Public Const RAS_MAXDEVICENAME As Integer = 128
Public Const RAS_RASCONNSIZE As Integer = 412
Public Const ERROR_SUCCESS = 0&
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Public Type RasEntryName
    dwSize As Long
    szEntryName(RAS_MAXENTRYNAME) As Byte
End Type

Public 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
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Public Declare Function RasEnumConnections Lib _
"rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As _
Any, lpcb As Long, lpcConnections As Long) As Long

Public Declare Function RasHangUp Lib "rasapi32.dll" Alias _
"RasHangUpA" (ByVal hRasConn As Long) As LongPublic gstrISPName As String
Public ReturnCode As Long
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Public 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
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub HangUp()
Dim i As Long
Dim lpRasConn(255) As RasConn
Dim lpcb As Long
Dim lpcConnections As Long
Dim hRasConn As Long
lpRasConn(0).dwSize = RAS_RASCONNSIZE
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(ByVal hRasConn)
        End If
    Next i
End If

End Sub
'
'''''''''''''''''''''''event call'''''''''''''''''''''''''''''''
'
      Call HangUp

Wayne
0
 
tubesoxxAuthor Commented:
Hi Juilette/ The code was just what i was looking for. I will award your points with an expert grade of course!
I would like one small question answered if you have the time: If I place the "Call HangUp" in the form load will it set there waiting for a connection before acting and if so assuming one tries more than once to make a connection, will it still work or do i have to come up with some more code ?
I hope you understand what I am trying to do with very limited knowledge of basic ! Just don't want anyone connecting to the internet when I am not home, expecially chat rooms.
Thanks Plenty
tubesoxx
0
 
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now