Library code snippets
Check for 'ActiveConnection' via WinInet
This bit of code will show you how to detect an active connection using the WinInet API.
I have seen many who use the Windows Registry to check for an active connection, this is fine but you also need to code for a Registry Wrapper or use a handy class like VBA's Registry one but this may cost you some size. So a convienent way is to use the winInet API to check for an active connection.
Dump this into a module and when you do something like 'Msgbox Connected()' you will get TRUE is its conencted and FALSE if it isn't.
Option Explicit
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (lpdwFlags As Long, lpszConnectionName As Long, dwNameLen As Long, ByVal dwReserved As Long) As Long
Public Function Connected() As Boolean
Dim lNameLen As Long
Dim lRetVal As Long
Dim lConnectionFlags As Long
Dim LPTR As Long
Dim lNameLenPtr As Long
Dim sConnectionName As String
sConnectionName = Space$(256)
lNameLen = 256
LPTR = StrPtr(sConnectionName)
lNameLenPtr = VarPtr(lNameLen)
lRetVal = InternetGetConnectedStateEx(lConnectionFlags, ByVal LPTR, ByVal lNameLen, 0&)
Connected = (lRetVal <> 0)
End Function
Smaller, reliable and most of all its using the Windows API which is far better than searching the Windows Registry for a certain KEY.
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
================ Internet ==================
||
================ Cable Modem ============
||
================ Netgear Router =========
|| || ||
===Laptop(Wireless)====PC1 (LAN)=====PC2 (LAN)===
If disconnect the cable modem but router is running this program/code still detects as connected to iNet. Only if I disconnect the LAN connection or remove PCMCIA wireless card, program says disconnected.
I need some code that will find out actual iNet is connected, not just the active connection to a router. An expert idea/opinion is appreciated. Thanks.
This thread is for discussions of Check for 'ActiveConnection' via WinInet.