Public Const RAS_MaxEntryName As Long = 256
Public Const RAS_MaxDeviceName As Long = 128
Public Const RAS_MaxDeviceType As Long = 16
Public Const RASCS_Connected As Long = &H2000
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 Type RASCONNSTATUS
dwSize As Long
rasconnstate As Long
dwError As Long
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS_MaxDeviceName) As Byte
End Type
Public Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (ByRef lprasconna As RASCONN, ByRef lpdword As Long, ByRef lpdword As Long) As Long
Public Declare Function RasGetConnectStatus Lib "rasapi32.dll" Alias "RasGetConnectStatusA" (ByVal hrasconn As Long, ByRef lprasconnstatusa As RASCONNSTATUS) As Long
Public Function VPNConnectionActive() As Boolean
'//---------------------------------------------------------------------------------------
'// Procedure : VPNConnectionActive
'// Datum/Tijd: 30-06-2004 / 15:09
'// Auteur : Rick Langevoort
'// Doel : Controleren of er een actieve VPN connectie is.
'// Revisie :
'//---------------------------------------------------------------------------------------
Dim lngConns As Long, lngConn As Long
Dim aRAS(255) As RASCONN, rasState As RASCONNSTATUS
On Error GoTo ErrHandler
aRAS(0).dwSize = 412
If RasEnumConnections(aRAS(0), 421888, lngConns) = 0 Then
'//Check to see if there are any VPN connections in those:
For lngConn = 0 To lngConns - 1
If StrComp(Left(StrConv(aRAS(lngConn).szDeviceType, vbUnicode), InStr(StrConv(aRAS(lngConn).szDeviceType, vbUnicode), Chr(0)) - 1), "vpn", vbTextCompare) = 0 Then
'//If so, check if one of them is connected:
rasState.dwSize = 160
If RasGetConnectStatus(aRAS(lngConn).hrasconn, rasState) = 0 Then
If rasState.rasconnstate = RASCS_Connected Then Exit For
End If
End If
Next lngConn
End If
VPNConnectionActive = lngConn < lngConns
Exit Function
ErrHandler:
MsgBox "Error in libmain.VPNConnectionActive: " & vbCrLf & vbCrLf & err.Description & " (" & CStr(err.Number) & ")", vbCritical, MSG_HEADER
End Function