您的位置:首页 > 编程语言 > VB

Vbscript 编写SecureCRT脚本

2013-12-11 11:48 281 查看

Creating ActiveX Scripts

[align=center][/align]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 SubNote: 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

[align=center][/align]脚本通过属性及方法和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 dlgSet dlg = crt.Dialogdlg.Prompt("Login:")2是可以直接引用.Or, in VBScript and Python, without creating the reference:crt.Dialog.Prompt("Login:") 详细的对象及参数可以参考SecureCRT帮助文档.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息