Application Object

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

    Arguments

    GetActiveTab

    Clipboard

    GetLastError

    Dialog

    GetLastErrorMessage

    FileTransfer

    GetScriptTab

    Screen

    GetTabCount

    ScriptFullName

    GetTab

    Session

    OpenSessionConfiguration

    Version

    Quit

    Window

    Sleep

 

Properties

 

ActivePrinter

Description

Returns or sets the name of the active printer.

Remarks

Read/Write string property.

VBScript

Syntax

crt.ActivePrinter [ = printerName ]

Example

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

crt.ActivePrinter = "\\SERVER\InkJet2"

MsgBox "Updated Printer"

End If

Python

Syntax

crt.ActivePrinter [ = printerName ]

Example

if crt.ActivePrinter != "\\SERVER\InkJet2":

  crt.ActivePrinter = "HP LaserJet 8000 Series PCL 5"

  crt.Dialog.MessageBox("Updated Printer")

 

Arguments

Description

Returns a reference to SecureCRT's Arguments object.

Remarks

In VBScript, object variables assigned from the Arguments property require the "Set" syntax. See the Arguments object documentation for a description of its properties.

VBScript

Syntax

Set object = crt.Arguments

Python

Syntax

object = crt.Arguments

 

Clipboard

Description

Returns a reference to SecureCRT's Clipboard object.

Remarks

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

VBScript

Syntax

Set object = crt.Clipboard

Python

Syntax

object = crt.Clipboard

 

Dialog

Description

Returns a reference to SecureCRT's Dialog object.

Remarks

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

VBScript

Syntax

Set object = crt.Dialog

Python

Syntax

object = crt.Dialog

 

FileTransfer

Description

Returns a reference to SecureCRT's FileTransfer object.

Remarks

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

VBScript

Syntax

Set object = crt.FileTransfer

Python

Syntax

object = crt.FileTransfer

 

Screen

Description

Returns a reference to SecureCRT's Screen object.

Remarks

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

VBScript

Syntax

Set object = crt.Screen

Python

Syntax

object = crt.Screen

 

ScriptFullName

Description

Returns the full path and filename of the currently running script.

Remarks

None.

VBScript

Syntax

Set object = crt.ScriptFullName

Python

Syntax

object = crt.ScriptFullName

 

Session

Description

Returns a reference to SecureCRT's Session object.

Remarks

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

VBScript

Syntax

Set object = crt.Session

Python

Syntax

object = crt.Session

 

Version

Description

Returns a string containing SecureCRT's version.

Remarks

Read-only string property

VBScript

Syntax

crt.Version

Example

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

Python

Syntax

crt.Version

Example

crt.Dialog.MessageBox("The version of SecureCRT is: " + crt.Version)

 

Window

Description

Returns a reference to SecureCRT's Window object.

Remarks

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

VBScript

Syntax

Set object = crt.Window

Python

Syntax

object = crt.Window

 

 

Methods

ClearLastError

Description

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

 

Remarks

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

VBScript

Syntax

crt.ClearLastError

Python

Syntax

crt.ClearLastError()

 

GetActiveTab

Description

Returns the Tab object associated with the tab or tiled session window that is currently selected in the GUI.

Remarks

None.

VBScript

Syntax

Set object = crt.GetActiveTab

Python

Syntax

object = crt.GetActiveTab()

 

GetLastError

Description

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

Remarks

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

VBScript

Syntax

varname = crt.GetLastError

Example

Sub Main()

    on error resume next

    CRT.Session.ConnectInTab("nowhere")

    errcode = crt.GetLastError

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

End Sub

Python

Syntax

varname = crt.GetLastError()

Example

def main():

    try:

        crt.Session.ConnectInTab("nowhere")

    except ScriptError:

        errcode = crt.GetLastError()

    crt.Dialog.MessageBox("Error Code: " + str(errcode))

main()

 

GetLastErrorMessage

Description

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

Remarks

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

VBScript

Syntax

varname = crt.GetLastErrorMessge

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

 

Python

Syntax

varname = crt.GetLastErrorMessage()

Example

def main():

    try:

        crt.Session.ConnectInTab("nowhere")

    except ScriptError:

        errmsg = crt.GetLastErrorMessage()

    crt.Dialog.MessageBox("Error Message: " + errmsg)

main()

 

This example would display:

  Error Message: Connection failed

 

GetScriptTab

Description

Returns the tab or tiled session window from which the script was started.

Remarks

None.

VBScript

Syntax

Set object = crt.GetScriptTab

Example

Set ScriptTab = crt.GetScriptTab

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

Python

Syntax

object = crt.GetScriptTab()

Example

ScriptTab = crt.GetScriptTab()

crt.Dialog.MessageBox("Tab which started this script is tab number: " +

                      str(ScriptTab.Index))

 

GetTabCount

Description

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

Remarks

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

VBScript

Syntax

varname = crt.GetTabCount

Python

Syntax

varname = crt.GetTabCount()

 

GetTab

Description

Returns the tab object of the specified index.

Remarks

This does not bring the tab or tiled session window to the foreground. When sessions are tabbed, the index for each tab object matches its position in the tab bar.  When sessions are tiled, the indexes of the tab objects may not match the indexes when tabbed, but will remain consistent while the sessions are tiled.

VBScript

Syntax

Set object = crt.GetTab(arg)

Python

Syntax

varname = crt.GetTab(arg)

 

OpenSessionConfiguration

Description

Loads the configuration for the specified session.

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.

VBScript

Syntax

Set object.OpenSessionConfiguration [SessionPath]

Example

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

Set objDConfig = crt.OpenSessionConfiguration("Default")

Python

Syntax

object.OpenSessionConfiguration([SessionPath])

Example

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

objDConfig = crt.OpenSessionConfiguration("Default")

 

Quit

Description

Causes SecureCRT to exit.

Remarks

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

VBScript

Syntax

crt.Quit

Python

Syntax

crt.Quit()

 

Sleep

Description

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

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.

VBScript

Syntax

crt.Sleep millisec

Example

' Send a CR and pause for one second

crt.Screen.Send vbCr

crt.Sleep 1000

Python

Syntax

crt.Sleep(millisec)

Example

# Send a newline and pause for one second

crt.Screen.Send("\n")

crt.Sleep(1000)