--- joko/ToolBox/Windows/VpnDial/src/Module_Main.bas 2005/10/08 01:01:45 1.7 +++ joko/ToolBox/Windows/VpnDial/src/Module_Main.bas 2005/11/22 22:20:11 1.9 @@ -52,29 +52,8 @@ ' Form_Main.Show 'Else - ' dial command - If cmdline.hasSwitch("dial") Then - - conName = cmdline.getArgument("dial") - On Error Resume Next - Set rasItem = RasEntries(conName) - If Err.Number = 0 Then - success = RasConnect(rasItem.entryname, rasItem.PhonebookPath) - Else - MsgBox "Unkown RAS-Connection """ & conName & """." - End If - On Error GoTo 0 - - ' hangup command - ElseIf cmdline.hasSwitch("hangup") Then - conName = cmdline.getArgument("hangup") - success = RasDisconnect(conName) - 'MsgBox success - - 'End If - ' run script - ElseIf cmdline.hasSwitch("script") And success = True Then + If cmdline.hasSwitch("script") And success = True Then script_name = cmdline.getArgument("script") If script_name <> "" Then script_args = Chr(34) & DetermineClientIP(conName) & Chr(34) & " " & Chr(34) & DetermineServerIP(conName) & Chr(34) @@ -87,7 +66,13 @@ conName = cmdline.getArgument("setup") If conName <> "" Then + On Error Resume Next Set rasItem = RasEntries(conName) + If Err.Number <> 0 Then + MsgBox "Error while accessing RAS entry """ & conName & """." & vbCrLf & "Probably it does not exist?" + End + End If + On Error GoTo 0 If cmdline.hasSwitch("gui") Then With Form_Credentials @@ -130,9 +115,32 @@ 'RasRetrieveConnectionHandler conName ConnectionName = conName ConnectionOnline = RasIsOnline(conName) + + If cmdline.hasSwitch("gui") Then + ShowTrayIcon Form_Main, getTrayIconTipText(ConnectionName, ConnectionOnline) + End If + + ' dial command + If cmdline.hasSwitch("dial") Then + doDial conName + End If + + ' monitor ras connection MonitorRASStatusAsync + End If + ' dial command + ElseIf cmdline.hasSwitch("dial") Then + conName = cmdline.getArgument("dial") + doDial conName + + ' hangup command + ElseIf cmdline.hasSwitch("hangup") Then + conName = cmdline.getArgument("hangup") + success = RasDisconnect(conName) + 'MsgBox success + End If 'End If @@ -158,7 +166,13 @@ rasItem.PhonebookPath = curEntry.PhonebookPath rasItem.Win2000_SystemPhonebook = curEntry.Win2000_SystemPhonebook + 'MsgBox rasItem.entryname + On Error Resume Next RasEntries.add rasItem, rasItem.entryname + If Err.Number = 457 Then + 'MsgBox "Error: Duplicate RAS entry. Don't know what to dial. This error should not occour." + End If + On Error GoTo 0 Next i End Sub @@ -210,5 +224,36 @@ End If ConnectionOnline = isOnline + + UpdateTrayIcon getTrayIconTipText(ConnectionName, ConnectionOnline) + End If End Sub + +Private Function getTrayIconTipText(conName As String, isOnline As Boolean) As String + Dim TipText As String + TipText = "VpnDial monitoring """ & conName & """: " + If isOnline Then + TipText = TipText & "online" + Else + TipText = TipText & "offline" + End If + getTrayIconTipText = TipText +End Function + + +Private Function doDial(conName As String) + + Dim rasItem As RasEntryData + Dim success As Boolean + + On Error Resume Next + Set rasItem = RasEntries(conName) + If Err.Number = 0 Then + success = RasConnect(rasItem.entryname, rasItem.PhonebookPath) + Else + MsgBox "Unknown RAS-Connection """ & conName & """." + End If + On Error GoTo 0 + +End Function