Vbscript 編寫SecureCRT指令碼

來源:互聯網
上載者:User
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協助文檔.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.