Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > General

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2006, 09:57 PM
samoki samoki is offline
Registered User
 
Join Date: Jun 2006
Posts: 24
How to call SecureCRT in a WSH script with parameter

I want to call SecureCRT in a external program use WSH with SecureCRT parameters.Full command:

Set WSH = WScript.CreateObject("WScript.Shell")
WSH.Run "C:\Program Files\SecureCRT\SecureCRT.exe /NOSAVE /TITLEBAR " &Title &" /SCRIPT " &GetPath &"\MainSCRTNew.vbs",1,False

Title & GetPath are variables.
This sentence can not work,windows give error "80070002".
Please give me some suggestion to resolve it.

Another,I want to let user to choice if he want leave at once,if not,program will auto quit after a few seconds.
If user choice not or waiting,I use sentence "crt.sleep 10000",but how can I choice yes or terminate the msgbox to run the rest sentences?
Reply With Quote
  #2  
Old 12-31-2006, 12:51 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by samoki
I want to call SecureCRT in a external program use WSH with SecureCRT parameters.Full command:

Set WSH = WScript.CreateObject("WScript.Shell")
WSH.Run "C:\Program Files\SecureCRT\SecureCRT.exe /NOSAVE /TITLEBAR " &Title &" /SCRIPT " &GetPath &"\MainSCRTNew.vbs",1,False

Title & GetPath are variables.
This sentence can not work,windows give error "80070002".
Please give me some suggestion to resolve it.
Error 80070002 translates to "The system cannot find the file specified."

In other words, your current script is set to run "C:\Program" with the following arguments:
Files\SecureCRT\SecureCRT.exe /NOSAVE /TITLEBAR ...

Try enclosing the path to SecureCRT.exe in "quotes". Here are two examples of how to accomplish this:

Escape quotes by using "" within VBScript strings:
WSH.Run """C:\Program Files\SecureCRT\SecureCRT.exe"" /NOSAVE /TITLEBAR " & Title & " /SCRIPT " & GetPath & "\MainSCRTNew.vbs", 1, False

or

Use chr(34) to represent a " character and concatenate with '&':
WSH.Run chr(34) & "C:\Program Files\SecureCRT\SecureCRT.exe" & chr(34) & " /NOSAVE /TITLEBAR " & Title & " /SCRIPT " & GetPath & "\MainSCRTNew.vbs", 1, False


Quote:
Another,I want to let user to choice if he want leave at once,if not,program will auto quit after a few seconds.
If user choice not or waiting,I use sentence "crt.sleep 10000",but how can I choice yes or terminate the msgbox to run the rest sentences?
SecureCRT's scripting API doesn't provide this natively, but you should be able to use the WScript.Shell.Popup() method. For example:
Code:
Sub Main()

    ' Prompt to see if we should exit early...
    If Not ContinueWithScript then exit sub

    MsgBox "Continuing with Script."
    
    ' remaining script code...
    
End Sub


Function ContinueWithScript()
' The WScript.Shell.Popup method is documented by Microsoft here:
' http://msdn.microsoft.com/library/en-us/script56/html/f482c739-3cf9-4139-a6af-3bde299b8009.asp
    nTimeout = 5
    Set a_shell = CreateObject("WScript.Shell")
    nResult = a_shell.popup("Would you like to exit right now?" & vbcrlf & _
        vbcrlf & _
        "After " & nTimeout & " seconds have passed, this script will " & _
        "continue if you do not respond.", _
        nTimeout, _
        "Exit Early Prompter (with timeout)" , _
        vbyesno)

    Select Case (nResult)
        Case vbno
            ContinueWithScript = False
            Exit Function
        Case else
            ' -1 means popup timed out... otherwise, vbyes would
            ' have been the value of nResult
            ' In this script, we don't care either way because
            ' the effect should be the same -- we'll continue
            ' with the script instead of exiting early.    
            ContinueWithScript = True
    End Select
End Function
--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 12-31-2006, 04:09 AM
samoki samoki is offline
Registered User
 
Join Date: Jun 2006
Posts: 24
New Question

Than you,the first question is resolved and the second I will test it in holiday or later than it.
When I call SecureCRT successfully in WSH script,SecureCRT run the second vbs script.In it,an error occured:
the sentences:

UnixUserName = crt.Dialog.Prompt ("Input username:",Title,UnixUserName,False)
UnixPassword = crt.Dialog.Prompt ("Input password:",Title,"",True)
does not work,scrt give me error:"unfinished string constant".
How can I resolve it?Would you mind help me?
Thank you.
Reply With Quote
  #4  
Old 12-31-2006, 11:11 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by samoki
UnixUserName = crt.Dialog.Prompt ("Input username:",Title,UnixUserName,False)
UnixPassword = crt.Dialog.Prompt ("Input password:",Title,"",True)
does not work,scrt give me error:"unfinished string constant".
Those two lines as you have provided them look OK, so I'm guessing the problem is somewhere else within the script.

The error "unfinished string constant" (otherwise known as "Unterminated string constant") you're seeing means that you have a line that has a starting quote (") without an ending quote (").

Consider the following example code line which generates an "Unterminated string constant" error:
MsgBox "Unterminated string

Note the leading quote (") coupled with the lack of a closing quote(").

The fixed line would be:
MsgBox "Fixed Unterminated string"

The error message reported by the VBScript engine typically will report the exact line on which the error occurs, and will even provide the context in which the error was found. For example, if the MsgBox "Unterminated string code were the only line of code in the script file, running the script within SecureCRT will result in the following error text reported by the VBScript engine:
Code:
---------------------------
SecureCRT
---------------------------
Microsoft VBScript compilation error

Error: Unterminated string constant
File: c:\temp\unterminated-String-Example.vbs
Line: 1

MsgBox "Unterminated string constant
---------------------------
OK   
---------------------------
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 01-03-2007, 09:58 PM
samoki samoki is offline
Registered User
 
Join Date: Jun 2006
Posts: 24
I found it,but can't resolve

I found the reason:the value of variable 'Title' is "Program is written by me",the value has spaces like "c:\program files\",and when program use the variable 'Title',error occued.Because I can't forecast which directory user will use,and some function/variable will get work directory,how can I resolve it ?
I have a test to use ""Title"" to resolve it,but in fact,it will show " "Program is written by me" ",it will show quotation mark with title that unwanted.This problem is more importantly about some variable to get work directory & some temp directory. Please give me some suggestion. Thanks!

Last edited by samoki; 01-03-2007 at 10:09 PM.
Reply With Quote
  #6  
Old 01-04-2007, 11:23 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Samoki,

It is very hard to answer this question with out the code from the script to place the question in context.

Would it be possible to get the code from the script that starts SecureCRT and script that is run from SecureCRT?

If you would rather not post the scripts on a public forum, please send them to me and mention this forum thread (# 2073).
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #7  
Old 01-04-2007, 08:40 PM
samoki samoki is offline
Registered User
 
Join Date: Jun 2006
Posts: 24
Some explain

I hope it can explain clearly:
Simple example:SCRT can read files.OK,I can write some code to get and record the working path in a file,when SCRT is starting,it will read the record file in appointed directory,then the variable get working path.And SCRT can do all I want in the working directory.
The question is if the value of variable has blank(or call 'space'),vbs in SCRT can't identify rightly.
Instance:
UnixUserName = crt.Dialog.Prompt ("Input username:",Title,"",False)
UnixPassword = crt.Dialog.Prompt ("Input password:",Title,"",True)

The value of variable 'Title' is "Program is written by Sam",when crt.Dialog.Prompt use it,error will occur.If I fix the sentences:

UnixUserName = crt.Dialog.Prompt ("Input username:",""Title"","",False)
UnixPassword = crt.Dialog.Prompt ("Input password:",""Title"","",True)
In program,title will show "xxxxxxxxxxxxx",in tile quotation marks "" is unwanted.

This is only simply explain,get path is more important than title.But,the hypostasis is the same.

Another,I access the link http://www.vandyke.com/feedback.php,but do not know which I should choose,technical support or bug report or any other one.

Last edited by samoki; 01-04-2007 at 09:19 PM.
Reply With Quote
  #8  
Old 01-05-2007, 09:54 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Samoki,

The technical support question will work fine.

I can definitely understand that having the extra quotes would not be wanted as part of the title or the path.

With the script, I will be able to give you more specific examples on how to work around this issue.

Please let me know if there are any issues sending the script.
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #9  
Old 01-06-2007, 10:04 AM
samoki samoki is offline
Registered User
 
Join Date: Jun 2006
Posts: 24
Hi,tnygren
Thank you for your support mail.I'll try it on Monday or a little later.
In question 2 I describe how equipment output.
When script in SecureCRT give device command by "crt.screen.send",if backup succeed,it will output "router#" then a blank line and then output "Backup data to server successfully!",at last output "router#" again.
Screen output is :
router#

Backup data to server successfully!

router#
At the same time,a monitor program is running in background.

I use the sentence 'crt.screen.synchrous = True',and use these sentence to recognise keywords:

If crt.Screen.WaitForString ("#",120) = True And crt.Screen.WaitForString("Backup data to server successfully!",120) = True Then
Log.WriteLine("Host backup succeeded at " &CurrentDate &" " &CurrentTime)
End If

another idea:

BackupFlag = crt.Screen.WaitForStrings (" Backup data to server successfully!", "Tftp server no response, confirm the server is working!" ,120)

Select Case BackupFlag
Case 1
Log.WriteLine("Host backup succeeded at " &CurrentDate &" " &CurrentTime)
...
waiting time is 120 seconds,is for timeout to wait failure information.
But these two methods are all useless.
Thanks again for you help,when I finish test depond on your answers,I will tell you.And new question might appear,I'll ask you again.

Last edited by samoki; 01-07-2007 at 09:46 PM.
Reply With Quote
  #10  
Old 01-08-2007, 11:46 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Samoki,

Quote:
But these two methods are all useless.
I'm not sure I understand what is happening.

Is the script not executing the code needed when this line is found?

Does anything appear on the screen?

Has the waitforstring function timed out before either line appeared on the screen?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
Reply

Thread Tools
Display Modes

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 02:50 AM.