This article explains the basics of controling your DUN([D]ial [U]p [N]etworking) via the WinInet API Function to see if theres an active connection, dial a connection if there isnt or hangup if there is.If your working on a browser based or something to do with the internet then this article may help you.
I've seen many people using the following to get the status of the internet connection:
Function ActiveConnection() As Boolean
Dim hKey As Long
Dim lpSubKey As String
Dim phkResult As Long
Dim lpValueName As String
Dim lpReserved As Long
Dim lpType As Long
Dim lpData As Long
Dim lpcbData As Long
ActiveConnection = False
lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult)
If ReturnCode = ERROR_SUCCESS Then
hKey = phkResult
lpValueName = "Remote Connection"
lpReserved = APINULL
lpType = APINULL
lpData = APINULL
lpcbData = APINULL
ReturnCode = RegQueryValueEx(hKey, lpValueName, lpReserved,
lpType, ByVal lpData, lpcbData)
lpcbData = Len(lpData)
ReturnCode = RegQueryValueEx(hKey, lpValueName, lpReserved,
lpType, lpData, lpcbData)
If ReturnCode = ERROR_SUCCESS Then
If lpData = 0 Then
ActiveConnection = False
Else
ActiveConnection = True
End If
End If
RegCloseKey (hKey)
End If
End Function
The above code was taken from a project by someone else, and I DON'T TAKE ANY CREDIT FOR IT. The code is alright if you arr prepared to add the API functions for the Windows Registry. But if your like me, I like to do things and keep the code to the minimal. I usually code my functions into a handy DLL (ActiveX DLL-[D]ynamic [L]ink [L]ibrary) which I use it mostly all my projects. Its easier and more efficent in some ways. If you were to add the above code to a DLL then you would add the registry code or add dependencies to one.
Comments