在不关闭应用程序或会话的情况下退出 Securecrt 脚本

Exit a Secure CRT script without clossing the application or session

我正在通过 Secure CRT 使用 vbscript,包含不同的子程序和全局变量,在主子程序之外,以便子程序可用。

我想问一下是否有一种方法可以在到达进程结束之前在任何需要的时候退出脚本而不使用 crt.Quit,因为最好有安全的 crt 运行ning 并可用于其他命令。

我的脚本如下

Intro = msgbox ("ONLY FOR AUTHORISED USE!!!", 1+16+0+4096)
    If Intro =2 Then
        MsgBox"Operation Cancelled"
    ThisIsTheEnd
    End If

DSLAM=inputbox ("Please Enter Dslam Name","Login")
    If DSLAM="" Then
        MsgBox"Operation Cancelled"
    ThisIsTheEnd
    End If

crt.Screen.Send "telnet " &  DSLAM & Chr(13)
crt.Screen.WaitForString "login:"
crt.Screen.Send "xxxx" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "xxxxxxxx" & Chr(13)
crt.Screen.WaitForString ">"
crt.Screen.Send "enable" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "xxxxxxxx" & Chr(13)
crt.Screen.WaitForString "#"
crt.Screen.Send "conf t" & Chr(13)
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "br" & Chr(13)
crt.Screen.WaitForString "#"

CARD=inputbox("Please Enter Dslam Card", "Dslam Card")
    If Card="" Then
        MsgBox"Operation Cancelled"
        crt.Screen.Send "end" & Chr(13)
        crt.sleep 500
        crt.Screen.Send "exit" & Chr(13)
        ThisIsTheEnd
    End If
    
PORT=inputbox("Please Enter Dslam Port", "Dslam Port")
    If Port="" Then
        MsgBox"Operation Cancelled"
        crt.Screen.Send "end" & Chr(13)
        crt.sleep 500
        crt.Screen.Send "exit" & Chr(13)
        ThisIsTheEnd
    End If  

Sub Main() 

Profile

NextAction

ThisIsTheEnd

End Sub

Sub Profile

SELPROFILE=inputbox("1.free_VDSL_8B_Default" & Chr(13) & "2.free_VDSL_12A" & Chr(13) & "3.free_VDSL_17A", "Please Select the Profile")
crt.Screen.Send "port lre" & " " & CARD & "/" & PORT & " disable" & Chr(13)
crt.sleep 500

    If SELPROFILE=1 Then
            MsgBox "Default 8B Profile Selected"
        crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_8B_Default" & Chr(13) 
        ElseIf SELPROFILE=2 Then
        MsgBox "12A Profile Selected"
        crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_12A" & Chr(13) 
    ElseIf SELPROFILE=3 Then 
        MsgBox "17A Profile Selected"
        crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_17A" & Chr(13)
    ElseIf SELPROFILE<>1 or 2 or 3 Then
        MsgBox "INVALID PROFILE!!!", 0+16+0+4096
        Profile
    End If 
    
crt.sleep 500
crt.Screen.Send "port lre" & " " & CARD & "/" & PORT & " enable" & Chr(13)
crt.sleep 500
crt.Screen.Send "end" & Chr(13)
crt.sleep 500
crt.Screen.Send "wr mem" & Chr(13)
crt.Screen.WaitForString "#"

End Sub 

Sub NextAction

GOON=inputbox("1.Exit" & Chr(13) & "2.Show Sync" & Chr(13) & "3.Repeat", "Please select next action")
    if GOON=1 then 
        crt.Screen.Send "exit" & Chr(13)
    ElseIf GOON=2 then 
        crt.Screen.Send "sho lre" & " " & CARD & "/" & PORT & " xdsl phys-table linerates" & Chr(13)
        NextAction
    ElseIf GOON=3 then
        crt.Screen.Send "conf t" & Chr(13)
        crt.Screen.WaitForString "(config)#"
        crt.Screen.Send "br" & Chr(13)
        crt.Screen.WaitForString "#"    
        Profile
    Else    MsgBox "INVALID SELECTION!!!", 0+16+0+4096
        NextAction  
    End if

End Sub

Sub ThisIsTheEnd

    MsgBox"Thank you, come again"
    crt.Quit

End Sub

总而言之,我希望可以选择在各个消息输入框阶段退出脚本,通过取消选项而不关闭 Secure CRT。

整个脚本必须 运行 通过安全 CRT,因此 WScript.Quit 不是一个选项。

感谢您的宝贵时间!

所以问题最终通过全局声明在 subs 上使用的变量、添加 Do Until Loop 并重新排列 subs 以便脚本可以以 Exit 和 End Sub 命令结束来解决。

看起来 End Sub(如果使用正确)足以在任何需要的时候终止脚本。