天天看點

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 SecureCRT

最常用的ActiveX Script engines有: VBScript and Jscript. ActiveX script engines可以通過标準接口同SecureCRT交流.是以SecureCRT可以執行VBScript腳本.

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接口的版本

# $language = "VBScript"

# $interface = "1.0"

Sub Main

  ' Display SecureCRT's version

 MsgBox "SecureCRT version is: " & crt.Version

End Sub

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

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放入到main函數中,不過可能有以下幾方面原因.

VBScript一般會先執行放在main函數外的程式.可用來初始化.

另一個原因是用Exit Sub終止一個程式的運作.

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

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:

繼續閱讀