首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > vbScript >

Vbscript 编纂SecureCRT脚本

2012-07-15 
Vbscript 编写SecureCRT脚本Creating ActiveX ScriptsActiveX script engines communicate with SecureCRT

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
   
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帮助文档.

 

热点排行