--- joko/ToolBox/Windows/VpnDial/src/Module_Main.bas 2005/10/06 20:15:34 1.3 +++ joko/ToolBox/Windows/VpnDial/src/Module_Main.bas 2005/10/07 20:25:24 1.4 @@ -16,6 +16,9 @@ ' http://www.dotnet247.com/247reference/msgs/18/93960.aspx Public RasEntries As New Collection +Public ConnectionName As String +Public ConnectionOnline As Boolean +Public ScriptName_Up As String, ScriptName_Down As String Sub Main() @@ -85,6 +88,27 @@ End If End If + + ' monitor + ElseIf cmdline.hasSwitch("monitor") Then + conName = cmdline.getArgument("monitor") + If conName <> "" Then + + If cmdline.hasSwitch("up") Then + ScriptName_Up = cmdline.getArgument("up") + End If + + If cmdline.hasSwitch("down") Then + ScriptName_Down = cmdline.getArgument("down") + End If + + 'Set rasItem = RasEntries(conName) + 'RasRetrieveConnectionHandler conName + ConnectionName = conName + ConnectionOnline = RasIsOnline(conName) + MonitorRASStatusAsync + End If + End If 'End If @@ -114,3 +138,41 @@ Next i End Sub + +' callback from MonitorRASStatusAsync +Public Sub detectOnlineOfflineChange() + Dim newState As Boolean + Dim script_name As String, script_args As String + Dim cmd As String + + newState = RasIsOnline(ConnectionName) + + If ConnectionOnline <> newState Then + 'MsgBox newState + + ' connection goes online + If newState = True Then + If ScriptName_Up <> "" Then + script_name = ScriptName_Up + End If + + ' connection goes offline + Else + If ScriptName_Down <> "" Then + script_name = ScriptName_Down + End If + + End If + + If script_name <> "" Then + script_args = Chr(34) & DetermineClientIP() & Chr(34) & " " & Chr(34) & DetermineServerIP() & Chr(34) + cmd = App.Path & "\" & script_name & " " & script_args + 'MsgBox cmd + On Error Resume Next + Shell cmd, vbHide + On Error GoTo 0 + End If + + ConnectionOnline = newState + End If +End Sub