Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-29-2014, 04:38 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
Cancel script without prompt

Hi.

I'm currently building a script where I want the script to be cancelled when one of the if statements is met.

See the example below:
Code:
result0 = crt.Screen.WaitForStrings("x","y")

if result0 = 1 Then
crt.screen.Send "hello"
end if

if result0 = 2 Then
crt.screen.SendSpecial "MENU_SCRIPT_CANCEL"
This works fine and the script is doing what it's supposed to.
The only problem is that when the script is cancelled a dialogbox is presented saying that the script was cancelled.
The only way to remove the dialogbox is to click the OK button.

Is there any way to cancel the script without receiving the dialogbox?
Reply With Quote
  #2  
Old 09-29-2014, 09:37 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
It is possible to accomplish your goal using VBScript error handling.

Here is an example:
Code:
On Error Resume Next
If result0 = 2 Then
    crt.screen.SendSpecial "MENU_SCRIPT_CANCEL"
End If
On Error Goto 0
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 09-30-2014, 02:18 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
I can't seem to get that command to work properly.

Here's the first part of my script where the canceling of the script might be necessary.

Code:
crt.Screen.Synchronous = True

'This part dnstelnet's the hostname or ip-address you have copied to your clipboard. #######

crt.screen.Send "telnet "
crt.screen.SendSpecial "MENU_PASTE" 
crt.screen.Send "" & vbCr

result0 = crt.Screen.WaitForStrings("Name or service not known","Connected to")
'Name or service not known = when it doesn't work to telnet the host.
'Connected to = when it works to telnet the host.

'If it doesn't work to telnet the host try to dnstelnet the host.
if result0 = 1 Then
crt.screen.Send "dnstelnet "
crt.screen.SendSpecial "MENU_PASTE" 
crt.screen.Send "" & vbCr

result3 = crt.Screen.WaitForStrings("has address","$","Connected to")

'If it doesn't work to dnstelnet the host because there's severeal hosts matching the criteria then cancel the script.
On Error Resume Next
if result3 = 1 Then
crt.screen.SendSpecial "MENU_SCRIPT_CANCEL" 
end if
On Error Goto 0

'If it doesn't work to dnstelnet the host because there's no hosts matching the criteria then cancel the script.
On Error Resume Next
if result3 = 2 Then
crt.screen.SendSpecial "MENU_SCRIPT_CANCEL" 
end if
On Error Goto 0

'If it works to dnstelnet the host then continue with the login.
if result3 = 3 Then
end if
end if


'If it works to telnet the host then continue with the login.
if result0 = 2 Then
end if
I don't know if I'm doing it right or if I misunderstood your response.
The script is cancelled but I'm still receiving a dialogbox.
Reply With Quote
  #4  
Old 09-30-2014, 10:26 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi e2script,

What version of SecureCRT are you using?

What is the text of the dialog box you are seeing when the script is cancelled?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 10-02-2014, 04:43 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
I'm using SeucreCRT version 6.6.3 and I have attached the message I receive.
Attached Images
File Type: jpg Scriptmessage.jpg (23.2 KB, 160 views)
Reply With Quote
  #6  
Old 10-03-2014, 05:06 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi e2script,

Thanks for the update. I am not sure why I got a false positive in my testing when I posted a potential solution.

I get the same behavior you get.

The alternative would be to put your code in some sort of structure like a Sub or a Function, and if you get the results you don't want, exit. For example:
Code:
Sub Main
    crt.Screen.Synchronous = True
    crt.Screen.Send vbcr
    nResult = crt.Screen.WaitForStrings("x", "y")

    If nResult = 1 Then
        MsgBox "Hello World!"
    End If

    If nResult = 2 Then
        Exit Sub
    End If
End Sub
How does this work for you?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:27 PM.