VanDyke Software

Scripting Examples

Scripting Examples

The following example scripts can be used with VanDyke Software products and focus primarily on SecureCRT.

Script examples are provided as .txt files. After saving an example script file to your system, you may need to change the extension from .txt to either .vbs or .py depending on whether it's a VBScript or Python example.

Note: These examples provide you with a starting point for creating your own scripting solutions. Although a script example may appear to do "exactly what you need", the scripts will almost always need to be modified to meet your own specific situation.

For additional information about scripts and scripting methods, see the Windows Scripting Examples page, the Python Scripting Examples page, the SecureCRT Scripting FAQ, and the VanDyke Software online Scripting Essentials guide.

VBScript and Python Examples for SecureCRT


Cisco Save Running/Startup Config to Local File (Python)
Written in Python and able to run on Windows/Linux/macOS versions of SecureCRT. If you're already connected to the device using SecureCRT, the script saves your Cisco router running-config or startup-config to a local file with the press of a button.

Color Scheme Scripting (Python)
Need to quickly adjust your colors based on existing color schemes defined in SecureCRT? Two example scripts show how you can save clicks while you enjoy rapid color scheme selection.
Watch the video: Color Schemes and ANSI Color Palettes

Command Window Automation (Python and VBScript)
Demonstrates how to automate the Command window in SecureCRT 7.2 and newer.

Connect in Tab to Host and Handle Authentication in Terminal Window (VBScript)
Prompts for host/IP, username, and password (if not hard-coded in the script variables strHost, strUser, and strPwd), and then uses the information to connect to the host using the SSH2 protocol. The session configuration object is used to detect if the option is enabled for handling authentication in the terminal window, and then prompts the user to have this script automatically enable it if the option is not currently enabled. SSH2 authentication is handled by waiting for the username and password prompts and then sending the username and password, respectively.

Connect to Hosts in the Clipboard (one per line) (Python)
Shows how to instruct SecureCRT to establish ad hoc connections to hosts listed one by one in the clipboard.

Get Configuration Path (Python and VBScript)
Shows how to acquire the folder/directory from which SecureCRT is loading/saving configuration settings. The cross-platform Python example will work in SecureCRT on Windows and macOS/Linux platforms. The VBScript example will work only in SecureCRT on Windows.

Get Tab By Name (Python and VBScript)
Shows how to get a reference to a tab object by supplying the tab name. Examples provided for both VBScript and Python.

Import Arbitrary Data From File to SecureCRT Sessions (Python)
Shows how to create sessions from information in a text file (.csv format by default, but you can edit to fit the format you have).

Import Keyword Highlighting INI File (Python)
This example demonstrates an easy way to import a Keyword Highlighting INI file into SecureCRT.
Watch the video: Keyword Highlighting in SecureCRT
Watch the video: Importing a Keyword INI File into SecureCRT

Import PuTTY Connections to SecureCRT Saved Sessions (VBScript)
Imports PuTTY configurations into SecureCRT saved sessions. Different example scripts are available to import from PuTTY, MPuTTY, PuTTY-CM, and Super PuTTY.

Importing Custom Modules Which Reference the "crt" Object (Python)
Provides examples showing techniques for importing custom-written Python modules which need to reference the crt scripting object.

Integrating with Microsoft Excel (VBScript)
Several examples demonstrating use of Excel to read, write, or search for data.

Iterate Over Saved Sessions (Python and VBScript)
Demonstrates how to iterate over all saved sessions to perform an action. Examples show how to export session data to a file (.csv or .ini/.conf format).

Jump Host — Handle Secondary Host Connection Attempts (Python and VBScript)
Are you connected to a jump host and want an example of automating SSH or Telnet connection attempts from that remote shell to another system? This example shows you a best practice way to accomplish this task.

Logging Status and Statistics in SecureCRT's Status Bar (Python)
An example of how to use a script to show SecureCRT's logging status (On|Off) and statistics (number of lines, size) in the status bar for the current tab or session.

Lookup Data from CSV File Using CSV Reader (Python)
Python example shows how to use the native Python CSV reader to read data from a CSV file and perform a lookup of related data coming from the same row in the file.

Open SecureCRT's Log File/Folder (Python and VBScript)
Shows how a script can be launched from a button to open SecureCRT's log file/folder.

Paste (or Send ASCII File) with Echo Flow Control (Python)
Demonstrates how to send data from the clipboard (or read in from a file) to a remote system, sending each line one at a time and waiting for prior lines to be echoed back by the remote system before moving on with sending subsequent lines.

Ping Host from Clipboard/Selection Using Local Shell Connection (Python)
Shows how to utilize the Local Shell capability of SecureCRT to launch a "ping" command for a specified host (the target host can be specified via the clipboard, selection in the terminal screen, or a prompt window).

Reveal Non-Printing Characters (Python and VBScript)
Demonstrates how to "reveal" non-printing characters that are present in the clipboard (with double-quotes, Carriage Return, Line Feed, etc., as examples of non-printing characters).

Run Commands on Multiple Hosts and Log Results (Python)
(Also known as: Read Data From Separate Hosts/Commands File and Log to Individual Files)
Demonstrates how to connect to hosts read in from a "hosts" file and for each host, send a list of commands read in from a "commands" file. Results are logged to separate, uniquely-named files based on the host address and optionally the commands that are executed.

Save Screen Text to a File (Python and VBScript)
Demonstrates how to easily and quickly save text from the screen/scrollback to a file. Three separate modes are available for deciding what text to save: selected text, all screen text, or all text on both screen and scrollback buffer.

Save Selected Text to CSV File (Python and VBScript)
Allows you to quickly save columns of space-separated data selected in SecureCRT's terminal screen to a CSV file. Automatically launches the CSV file for viewing/editing in the system's default CSV app.

Send Command With Date/Time Substitutions (Python)
An example which allows SecureCRT to automatically convert date/time substitution parameters (e.g., %Y, %M, %D, etc.) when sending a command.

Set Trace Level (Python and VBScript)
Shows how to set a more/less verbosity level for SecureCRT's "Trace Options" functionality. Often when troubleshooting a connectivity issue between client and server, it's helpful to know more about what's going on lower down in the protocol. If VanDyke Software technical support asks you to set Trace Level to a value greater than one, consider this script as an alternative to manually editing the .ini file.

SFTP Tab Automation (Python and VBScript)
Demonstrates opening an SFTP tab and programmatically driving a file download. Prior to running this script, the currently active tab must already be connected with the SSH2 protocol to a remote server that is capable of providing SFTP functionality; otherwise an error will occur and script execution will be halted.
Watch the video: The SFTP Tab in SecureCRT

Store Command Results in the Clipboard (VBScript)
Example script which made an appearance in the Advanced Copy and Paste in SecureCRT video on our YouTube channel. It can be used to automatically copy results of remote commands into the clipboard (so you don't even have to spend valuable time selecting the results with your mouse).

TAPI Replacement Dialer — Use Serial (VBScript)
This Windows-only example script shows one alternative to using TAPI. It uses the Serial protocol to connect to the COM port of your modem, and does the dialing instead of farming the job off to the Windows TAPI system.

Use "Description" Field of Saved Sessions as Script Argument (Python and VBScript)
Shows how you can use the Description field of a saved session to store data that you need to use somewhere within your script, but you don't want to hard-code it (because it might be session-specific, for instance).

Word Delimiter Rotation (Python)
Shows one way of cycling through different delimiter sets for double-click word selection. Having mapped a button on SecureCRT's button bar to run this script, SecureCRT's word delimiters for the active session will change with each button press, rotating through five different word delimiter set examples.

VanDyke Software uses cookies to give you the best online experience. Before continuing to use this site, please confirm that you agree to our use of cookies. Please see our Cookie Usage for details.