Application Object

From SecureCRT

SecureCRT Icon  Application Object


 

Description

Top-level object. Provides access to all of SecureCRT's properties and methods.

 

Syntax

crt.Property [ = expression ]

crt.Method([arglist])

 

Remarks

The name crt is used to access all of SecureCRT's top-level properties and methods. Some of these top-level properties return references to other objects. When a script is run by SecureCRT it is not necessary to create the crt object. It is automatically part of the script namespace.

 

Application Object Properties and Methods

Properties

Methods

    ActivePrinter

    ClearLastError

    Clipboard

    GetLastError

    Dialog

    GetLastErrorMessage

    FileTransfer

    GetScriptTab

    Screen

    GetTabCount

    Session

    GetTab

    Version

    OpenSessionConfiguration

    Window

    Quit

 

    Sleep

 

Properties

 

ActivePrinter

Description

Returns or sets the name of the active printer.

Syntax

crt.ActivePrinter [ = printerName ]

Remarks

Read/Write string property.

Example:

If crt.ActivePrinter <> "\\SERVER\InkJet2" Then

crt.ActivePrinter = "\\SERVER\InkJet2"

MsgBox "Updated Printer"

End If

 

Clipboard

Description

Returns a reference to SecureCRT's Clipboard object.

Syntax

Set object = crt.Clipboard

Remarks

Object variables assigned from the Clipboard property require the "Set" syntax. See the Clipboard object documentation for a description of its properties.

 

Dialog

Description

Returns a reference to SecureCRT's Dialog object.

Syntax

Set object = crt.Dialog

Remarks

Object variables assigned from the Dialog property require the "Set" syntax. See the Dialog object documentation for a description of its properties and methods.

 

FileTransfer

Description

Returns a reference to SecureCRT's FileTransfer object.

Syntax

Set object = crt.FileTransfer

Remarks

Object variables assigned from the FileTransfer property require the "Set" syntax. See the FileTransfer object documentation for a description of its properties and methods.

 

Screen

Description

Returns a reference to SecureCRT's Screen object.

Syntax

Set object = crt.Screen

Remarks

Object variables assigned from the Screen property require the "Set" syntax. See the Screen object documentation for a description of its properties and methods.

 

Session

Description

Returns a reference to SecureCRT's Session object.

Syntax

Set object = crt.Session

Remarks

Object variables assigned from the Session property require the "Set" syntax. See the Session object documentation for a description of its properties and methods.

 

Version

Description

Returns a string containing SecureCRT's version.

Syntax

crt.Version

Remarks

Read-only string property

 

Example:

MsgBox "The version of SecureCRT is: " & crt.Version

 

Window

Description

Returns a reference to SecureCRT's Window object.

Syntax

Set object = crt.Window

Remarks

Object variables assigned from the Window property require the "Set" syntax. See the Window object documentation for a description of its properties and methods.

 

 

Methods

ClearLastError

Description

Resets the response from GetLastError and GetLastErrorMessage to ERROR_SUCCESS and "The operation completed successfully."

 

Syntax

crt.ClearLastError

Remarks

This is intended to be used in conjunction with GetLastErrorMessage so that the user can determine where the error came from.

 

GetLastError

Description

Returns the error code of the script exception that most recently happened.

Syntax

varname = crt.GetLastError

Remarks

This is most useful when the script is in the "resume next" error mode, meaning the script keeps executing even if errors happen.

 

Example:

Sub Main()

    on error resume next

    CRT.Session.ConnectInTab("nowhere")

    errcode = crt.GetLastError

    crt.Dialog.MessageBox "Error Code: " & errcode

End Sub

 

GetLastErrorMessage

Description

Returns the error text of the script exception that most recently happened.

Syntax

varname = crt.GetLastErrorMessge

Remarks

This is most useful when the script is in the "resume next" error mode, meaning the script keeps executing even if errors happen.

 

Example:

Sub Main()

    on error resume next

    CRT.Session.ConnectInTab("nowhere")

    errmsg = crt.GetLastErrorMessage

    crt.Dialog.MessageBox "Error Message: " & errmsg

End Sub

 

This example would display:

Error Message: Connection failed

 

GetScriptTab

Description

Returns the tab from which the script was started.

Syntax

Set object = crt.GetScriptTab

Remarks

Example:

 

Set ScriptTab = crt.GetScriptTab

MsgBox "Tab which started this script is tab number: " & ScriptTab.index

 

GetTabCount

Description

Returns the number of tabs (connected or not) that exist in the current SecureCRT window.

Syntax

varname = crt.GetTabCount

Remarks

Return value will always be greater than 0 (zero).

 

GetTab

Description

Returns the tab object of the specified index.

Syntax

Set object = crt.GetTab(arg)

Remarks

This does not bring the tab to the foreground.

 

OpenSessionConfiguration

Description

Loads the configuration for the specified session.

Syntax

Set object.OpenSessionConfiguration [SessionPath]

Remarks

SessionPath is a string parameter that is the relative path of the session. Returns a Config object. If SessionPath is not specified, the Default session's configuration object is returned. To access the session configuration associated with an active connection, use crt.Session.Config or objTab.Session.Config.

 

Example:

Set objConfig1 = crt.OpenSessionConfiguration("Routers\Telnet\Session1")

Set objDConfig = crt.OpenSessionConfiguration("Default")

 

Quit

Description

Causes SecureCRT to exit.

Syntax

crt.Quit

Remarks

A script that invokes Quit will be terminated immediately and cause SecureCRT to exit.

Sleep

Description

Specifies the time (in milliseconds) to pause the script's execution.

Syntax

crt.Sleep millisec

Remarks

The amount of time that it takes to execute the Sleep() method itself is a factor in how long the script pauses. Therefore, the accuracy of invoking Sleep with small values of 1 or 10 milliseconds will be affected by this overhead.

 

Example:

' Send a CR and pause for one second

crt.Screen.Send vbCr

crt.Sleep 1000