Scripts written in AbsoluteTelnet / SSH are written in VBScript. You can write global login scripts, session-specific login scripts, or user-initiated scripts. For more information about where you can attach various scripts and why you would want to put them there, read the information here.
This document is not intended to be a VBScript tutorial. There are plenty of resources on the web for that. What this document tries to do is convey how to implement scripts within AbsoluteTelnet, including the AbsoluteTelnet-specific scripting API, descriptions, and some examples.
All scripts in AbsoluteTelnet begin and end the same way. The script begins with ‘Sub Main’ and ends with ‘End Sub’. This marks the beginning and ending of your script. Everything in-between must be VBScript or use the AbsoluteTelnet scripting extensions.
Sub Main [your script here] End Sub
The following commands extend the VBScript command language with AbsoluteTelnet specific commands. The required input parameters and result codes are documented here, along with a description of what the function does. The VBScript functions were first added in version 7, then more were added in version 8 (below). In version 8, these functions are also available in the ActiveX interface.
AbsoluteTelnet Version 7
WaitFor "string"
– Waits for an indefinite amount of time for the text “string” to be sent from the host. This function returns a BOOLEAN TRUE or FALSE to indicate whether the text was received. Because there is no timeout on this function, the only time it will return FALSE is when the session terminals and the script ends
WaitForTimeout "string", timeout
– Waits for [timeout] milliseconds for the text “string” to be sent from the host. The function returns a BOOLEAN TRUE or FALSE to indicate whether the text was received. TRUE indicates the text was received and FALSE indicates that either the amout of time to wait was exhausted or the session ended before the script could complete.
SendText "string
” – sends “string” to the host using the current session. The function returns TRUE if the send was successfull and FALSE otherwise.
SendKey "key"
– sends a terminal special key press to the host using the current session. For example, SendKey “F7” will send a function-key press to the host. This function relies on the current terminal emulation to map “F7” to the appropriate escape sequence (an xterm F7 is different from a Wyse60 F7 for instance). The function will return TRUE if the send was successful and FALSE otherwise.
GetHostname
– does not take any parameters, but returns the current hostname as a string return parameter.
SetHostname "hostname"
– allows you to set the hostname using the script. This may not have an immediate effect, but will be used as the hostname if you disconnect and reconnect. Returns nothing.
SetAnswerback "message"
– allows you to programatically set the answerback message. Returns nothing.
Print "text"
– print “text” at the current cursor position on the screen. This is useful for printing script output and diagnostic messages on the screen while the script is running. Returns nothing.
PrintScreen
– Used to print the contents of the screen to the printer. This performs the same function as the print button on the toolbar. Returns nothing.
OpenLog "logfile
” – Opens the AbsoluteTelnet session log and returns a BOOLEAN TRUE or FALSE to indicate whether it was successful. This performs a similar function to the File->Open LOG in the GUI but the logfile name can be constructed by the program and the logfile can be opened automatically at login time.
CloseLog
– Closes the logfile opened by OpenLog
AbsoluteTelnet Version 8
GetText y1 x1 y2 x2
– Returns text from the screen in the rectangle defined by y1,x1 y2,x2.
SetConnectionType "ConnectionType"
– Sets the connection type for the terminal session. Values for ConnectionType can be “telnet”, “ssh”, “ssh1”, “ssh2”, “serial”, and “tapi”. Returns nothing.
SetConnectionPort PortNumber
– Sets the connection port number, for those connection types that use an internet connection (telnet, ssh1, ssh2) The default port for ssh1 and ssh2 is 22. The default port for telnet is 23. Returns nothing.
SetConnectionHost "hostname"
– Sets the hostname for those connection types that use an internet connection (telnet, ssh1, ssh2). Returns nothing.
SetEmulationType "EmulationType"
– Sets the emulation type. Values for EmulationType can be “vt100”, “vt220”, “vt320”, “ansi”, “xterm”, “qnx”, “vt52”, “scoansi”, “ansibbs” and “wyse60”. Returns nothing.
SetSSHCompressionLevel "Lev
el” – Used to set the compression level for ssh1 and ssh2 connection types. Takes an integer “Level” between 0 and 10. Returns nothing.
SetSSHAuthenticationType "Type"
– Used to set the type of authentication to use for ssh1 and ssh2 connections. Valid values are “password”, “publickey”, “smartcard”, and “gssapi”. Returns nothing.
SetSSHUsername "username"
– Used to set the username for ssh1 and ssh2 connections. Returns nothing.
SetSSHPassword "password"
– Used to set the password for ssh1 and ssh2 connections. Returns nothing.
SetFont "font", charset, translation
– Used to set the font and character set translation for the terminal connection. Returns nothing
Connect "timeout"
– Used to initiate the connection to the host. If the connection cannot be accomplished within “timeout” milliseconds, the function will fail. Returns a boolean to describe whether the connection was completed or failed.
Disconnect
– Disconnects the current connection
GetCursorXPosition
– Returns the zero-based X position of the cursor. (the left side of the screen is zero)
GetCursorYPosition
– Returns the zero-based Y position of the cursor (the top side of the screen is zero)
SetTerminalDimensions "columns" "rows" "fixed"
– Resize the terminal screen to the given size. The third parameter “fixed” is a boolean that describes whether the screen dimensions are allowed to change. Values are true or false. Returns nothing.
LockKeyboard "lock"
– Locks (or unlocks) the keyboard to prevent (or allow) input. The parameter “lock” is a boolean that determins wheter to lock or unlock the keyboard. Values can be true or false. Returns nothing.
BringToFront
– Affects the whole AbsoluteTelnet window and brings it above all other windows. Returns nothing.
SetColorTable "index", "red", "green", "blue"
– changes the color table. Most terminal types use 16 colors. However, xterm has a 256 color option. This function can be used to change the color definitions of any of these colors. The “index” is a zero-based index of the color definition. “Red”, “green”, and “blue” parameters are used to set the new RGB value of the color.
MakeActiveTab
– Makes the tab running the script the active tab. Returns nothing.
SetTabTitle "Title"
– sets the title of the current tab.
Pingback: AbsoluteTelnet – VBScripting – Celestial Software