How do I check if a user is online?
-
I have created a program that will access a webpage online using the built-in web browser in visual basic 2005 express, but if the user is NOT online, they get an ugly "Page Cannot Be Displayed" page. I want to be able to validate that the user is online so that I can redirect them to a custom page that I will store on their hard drive if necessary. I am fairly new to vb, and would appreciate any help I can get. Thanks in advance!!
-
I have created a program that will access a webpage online using the built-in web browser in visual basic 2005 express, but if the user is NOT online, they get an ugly "Page Cannot Be Displayed" page. I want to be able to validate that the user is online so that I can redirect them to a custom page that I will store on their hard drive if necessary. I am fairly new to vb, and would appreciate any help I can get. Thanks in advance!!
I got the following code from http://www.devx.com/vb2themax/Tip/19159[^] I haven't tested it, but it appears to be just a matter of making sure the wininet.dll is in the system directory and then calling IsConnectedToInternet function from your code. If it returns true you're connected, if false you're not. They you just change the location based on the response. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef _ lpSFlags As Long, ByVal dwReserved As Long) As Long Const INTERNET_CONNECTION_MODEM = 1 Const INTERNET_CONNECTION_LAN = 2 Const INTERNET_CONNECTION_PROXY = 4 Const INTERNET_CONNECTION_MODEM_BUSY = 8 ' return True if there is an active Internect connection ' ' optionally returns the connection mode through ' its argument (see INTERNET_CONNECTION_* constants) ' 1=modem, 2=Lan, 4=proxy ' 8=modem busy with a non-internet connection Function IsConnectedToInternet(Optional connectMode As Integer) As Boolean Dim flags As Long ' this ASPI function does it all IsConnectedToInternet = InternetGetConnectedState(flags, 0) ' return the flag through the optional argument connectMode = flags End Function
-
I got the following code from http://www.devx.com/vb2themax/Tip/19159[^] I haven't tested it, but it appears to be just a matter of making sure the wininet.dll is in the system directory and then calling IsConnectedToInternet function from your code. If it returns true you're connected, if false you're not. They you just change the location based on the response. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef _ lpSFlags As Long, ByVal dwReserved As Long) As Long Const INTERNET_CONNECTION_MODEM = 1 Const INTERNET_CONNECTION_LAN = 2 Const INTERNET_CONNECTION_PROXY = 4 Const INTERNET_CONNECTION_MODEM_BUSY = 8 ' return True if there is an active Internect connection ' ' optionally returns the connection mode through ' its argument (see INTERNET_CONNECTION_* constants) ' 1=modem, 2=Lan, 4=proxy ' 8=modem busy with a non-internet connection Function IsConnectedToInternet(Optional connectMode As Integer) As Boolean Dim flags As Long ' this ASPI function does it all IsConnectedToInternet = InternetGetConnectedState(flags, 0) ' return the flag through the optional argument connectMode = flags End Function
I'm really new to vb and don't understand this code or how to use it... Does anyone out there know how I can impliment this into my program... Thanks.