|
-
Jun 15th, 2000, 11:13 PM
#1
Im trying to write a program that will AutoConnect to the internet(like Internet Explore for example).
But more important is for the program to AutoDisconnect from the internet as it's closed(under the assumption that no othere program is currently using the internet connection) for example - IE disconnects at closing.
How could this be done
-
Jun 15th, 2000, 11:46 PM
#2
_______
'disconnect''''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 Long
Public 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
'connect'==============================================='open a browser and go to a www address
'bas module
'
Public Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Function ShellToBrowser%(Frm As Form, ByVal URL$, ByVal WindowStyle%)
Dim api%
api% = ShellExecute(Frm.hwnd, "open", URL$, "", App.Path, WindowStyle%)
'Check return value
If api% < 31 Then
'error code - see api help for more info
Dim msg As String
msg = "This item doesn't work with your system"
MsgBox msg, vbCritical, "Error"
ShellToBrowser% = False
ElseIf api% = 32 Then
'no file association
Dim msg1 As String
msg1 = "This item doesn't work with your system"
MsgBox msg, vbCritical, "Error"
ShellToBrowser% = False
Else
'It worked!
ShellToBrowser% = True
End If
End Function
'
'<<< event from application...click event of button >>>>>>>>
'
Private Sub cmdWeb_Click()
Dim Site As String
Dim success As Integer
Site = "http://www.Yahoo.com/" '& Trim(txtWeb.Text)
success% = ShellToBrowser(Me, Site, 0)
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jun 17th, 2000, 06:33 AM
#3
Thanks alot
Now after you've helped me you might want to know what it's all about well im looking for a way to make mIRC send an information for the program ON DCC complete and for the program to disconnect.
it is meant for a script i've built that will be used as a server for most of the time so when a home user downloads a hugh fule it can go to bed and not find his internet connection open the next day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|