Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detect connection/disconnection to net

Status
Not open for further replies.

ADoozer

Programmer
Dec 15, 2002
3,487
AU
i would like to have my app detect a conection to the net, log the time, detect a disconnection from the net, log the time then save these 2 times to a TimeLog.txt file.

i tried a little experimentation using winsocks listen method, but cant figure out how to detect the connection/disconnection

thanx all in advance
 
Would a routine that ran on a timer and checked the connection state be acceptable or do you only want it triggered on connect/disconnect?
 
idealy i would want the app to start when windows starts and wait for a connection.

however if you have an idea using timer i will sure give it a try.
 
Ok - this is something I have just done that checks if there is an internet connection

'*****************************************

'API Declaration
Declare Function InternetGetConnectedState Lib "wininet.dll " (ByVal lpconnecttype As Long, ByVal dwReserved As Long) As Long

'function
Public Function ConnectedToInternet() As Boolean

On Error GoTo FUNC_ERROR

'Determines if there is an active internet connection
'Returns True if there is

Dim connecttype As Long
Dim result As Long

result = InternetGetConnectedState(connecttype, 0&)
If result Then
ConnectedToInternet = True
Else
ConnectedToInternet = False
End If

Exit Function

FUNC_ERROR:
Debug.Print Err.Description

End Function

'************************************************

You could put a call to this function inside a timer.

If you look up InternetGetConnectedState on MSDN you will find that you can get more information about the connection (connecttype) if required. There are also API's that can force a connection/disconnection.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top