Wenn Sie den Überblick behalten möchten, weil Sie
    tagtäglich mehrere RAS Verbindungen nutzen, dann können Sie mit diesem Tipp alle
    Verbindungszeiten aufzeichnen. Dabei wird die Zählung fortgesetzt, wenn eine geschlossene
    Verbindung wieder aufgebaut wird. 
     
    1. Form und Objekte 
    Für ein Demoprojekt benötigen Sie erstens einen Timer, dessen Intervall Sie auf 1000
    setzen (also 1 Sek.). Desweiteren sollen die Verbindungsnamen und deren Zeiten in einem
    ListView Objekt dargestellt werden. Fügen Sie dazu das MS Windows Common Controls, über
    Komponenten, Ihrem Projekt hinzu und plazieren Sie ein ListView Objekt auf Ihrer Form. 
     
    2. Allgemein/Deklarationen 
    Private Declare Function RasEnumConnections Lib "RasApi32.dll" Alias
    "RasEnumConnectionsA" (lpRasConn As Any, lpcb As Long, lpcConnections As Long)
    As Long 
    Const RAS_MAXENTRYNAME As Integer = 256 
    Const RAS_MAXDEVICETYPE As Integer = 16 
    Const RAS_MAXDEVICENAME As Integer = 128 
    Const RAS_RASCONNSIZE As Integer = 412 
    Const ERROR_SUCCESS = 0 
     
    Private 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 
     
    3. Allgemein/ByteToString 
    'Werte umwandeln BYTE > STRING 
    Public Function ByteToString(ByteArray() As Byte) As String 
     
    Dim i As Integer 
     
    ByteToString = "" 
    i = 0 
     
    Do While ByteArray(i) <> 0 
       ByteToString = ByteToString & Chr(ByteArray(i)) 
       i = i + 1 
    Loop 
     
    End Function 
     
    4. Allgemein/toTime 
    'Zeitformat 
    Private Function toTime(ByVal x As Single) As String 
     
    toTime = Format(x Mod 60, "00") 
    toTime = ":" & toTime 
    x = x \ 60 
    toTime = Format(x Mod 60, "00") & toTime 
    toTime = ":" & toTime 
    x = x \ 60 
    toTime = x & toTime 
     
    End Function 
     
    5. Allgemein/CheckRASConnections 
    'Prüfen der Verbindungen 
    Sub CheckRASConnections() 
     
    Dim i As Long 
    Dim RasConn(255) As RasConn 
    Dim structSize As Long 
    Dim ConnectionsCount As Long 
    Dim ret As Long 
    Static LastTime As Single 
    Dim ElapsedTime As Single 
     
    If LastTime = 0 Then LastTime = Timer 
     
    RasConn(0).dwSize = RAS_RASCONNSIZE 
    structSize = RAS_MAXENTRYNAME * RasConn(0).dwSize 
    ret = RasEnumConnections(RasConn(0), structSize, ConnectionsCount) 
    ElapsedTime = Timer - LastTime 
     
    If ElapsedTime < 0 Then ElapsedTime = 0 
     
    If ret = ERROR_SUCCESS Then 
    For i = 0 To ConnectionsCount - 1 
     
    On Error GoTo NewConnection 
     
    Form1.ListView1.ListItems("K" & RasConn(i).hRasConn).Tag =
    Form1.ListView1.ListItems("K" & RasConn(i).hRasConn).Tag + ElapsedTime 
    Form1.ListView1.ListItems("K" & RasConn(i).hRasConn).Text =
    ByteToString(RasConn(i).szEntryName) & "-" &
    toTime(Form1.ListView1.ListItems("K" & RasConn(i).hRasConn).Tag) 
    GoTo NextConnection 
    NewConnection: 
     
    Form1.ListView1.ListItems.Add , "K" & RasConn(i).hRasConn,
    ByteToString(RasConn(i).szEntryName) 
    Form1.ListView1.ListItems("K" & RasConn(i).hRasConn).Tag = 0 
    NextConnection: 
     
    Next 
    End If 
     
    LastTime = Timer 
     
    End Sub 
     
    6. Funktionsaufruf Timer1.Timer 
    CheckRASConnections |