Vbscript 編寫SecureCRT腳本

Creating ActiveX Scripts


ActiveX script engines communicate with SecureCRT via standard interfaces. Therefore, SecureCRT can host any compliant script engine to run your scripts. The advantage of this approach is that you can script SecureCRT using the language of your choice. If an ActiveX script engine is available for your preferred scripting language, you can write scripts that will work with SecureCRTapp

最經常使用的ActiveX Script engines有: VBScript and Jscript. ActiveX script engines能夠經過標準接口同SecureCRT交流.因此SecureCRT能夠執行VBScript腳本.ide

Script headers will be used by SecureCRT to identify which script language the script is written in and the version of SecureCRT scripting interface. Each line of the script header must begin with a (#) character. A SecureCRT script header includes a $language line that identifies the script engine and an $interface line to identify SecureCRT's interface version.函數

頭文件用來標識用的是什麼腳本語言和interface用來標識SecureCRT接口的版本ui

# $language = "VBScript"
# $interface = "1.0"

Sub Main
  ' Display SecureCRT's version
 MsgBox "SecureCRT version is: " & crt.Version
End Subthis

Note: A SecureCRT script header may also contain blank lines that begin with (#).spa

It is not a requirement that you place your code within a main however there may be reasons why you would want to do this. The VBScript and JScript engines will parse and execute global script code (script code you have defined outside of any subroutine) before your main is executed. If you have "initialization" code that you want to ensure has been completely executed before your actual script code begins, it may be useful to place your initialization code at the global level. This will ensure that your initialization code will all execute before your main code runs.code

並非必須把code放入到main函數中,不過可能有如下幾方面緣由.對象

VBScript通常會先執行放在main函數外的程序.可用來初始化.接口

另外一個緣由是用Exit Sub終止一個程序的運行.ip

Another reason you may want a main routine is to allow your scripts a way of aborting themselves in case of problems. In VBScript there is no built-in way of exiting a script at the global level. However, if you want to exit a subroutine it is possible to use the Exit Sub syntax to do so. For example, in VBScript:

Sub Main

 condition = DoSomething()
  If condition = 0 Then
    ' Error, bailout
    Exit Sub
  End If

End Sub

Overview of SecureCRT Script Objects


腳本經過屬性及方法和SecureCRT進行交互.若是要引用SecureCRT的object通常以crt.開始

Scripts interact with SecureCRT by invoking properties and methods on SecureCRT's "top-level" or Application object or by invoking the properties and methods on "sub-objects" available through SecureCRT's application object. SecureCRT's application object is accessed in scripts with the name ‘crt’. Properties and methods on SecureCRT's sub-objects may be accessed by creating a reference to a sub-object, or through the use of VBScript’s multiple dot syntax. For example:

子對象的引用有兩種方法.

1是首先創建父對象,經過父對象引用子對象.

Dim dlg

Set dlg = crt.Dialog

dlg.Prompt("Login:")

2是能夠直接引用.

Or, in VBScript and Python, without creating the reference:

crt.Dialog.Prompt("Login:")

詳細的對象及參數能夠參考SecureCRT幫助文檔.

相關文章
相關標籤/搜索