Xshell 5 supports vbs, javascript, and python scripting languages and utilizes its own unique API. Using this API, users can automate repetitive tasks to not only save time but improve workflow. The following article will explain two APIs which have been included in Xmanager Enterprise 5 Build 0811 and Xshell 5 Build 0831, the Dialog.Prompt and the Dialog.MessageBox.
xsh.Dialog.Prompt
The xsh.Dialog.Prompt function displays a dialog prompt which incorporates a message and input field.
xsh.Dialog.MessageBox
The xsh.Dialog.MessageBox function displays a message box and a variety of buttons. (e.g. OK, Cancel, Abort, Retry, etc.)
How to Execute a Script
- In your preferred text editor write a script using either vbs, javascript, or python.
- Open Xshell and navigate to the Tools -> Script -> Run. Browse to your script file and click Open.
- If you want to end the script navigate to Tools -> Script -> Cancel.
Script Sample (Visual Basic)
Sub Main Dim hostname, username, password hostname = xsh.Dialog.Prompt ("Insert Hostname", "Prompt Dialog", "hostname", 0) username = xsh.Dialog.Prompt ("Username", "Prompt Dialog", "", 0) password = xsh.Dialog.Prompt ("Password", "Prompt Dialog", "", 1) if xsh.Dialog.MessageBox("Connect to " & hostname & " server", "MessageBox",1) = 1 then xsh.Session.Open("ssh://" & username & ":" & password & "@" & hostname) End If End Sub
Function Prototypes
string xsh.Dialog.Prompt(LPCTSTR lpszMessage, LPCTSTR lpszTitle, LPCTSTR lpszDefault, BOOL bHidden)
Description
- Returns user’s input from Prompt Dialog Box
Return Values
- User’s input from Prompt Dialog Box
Parameters
- lpszMessage
The string to be displayed in the Prompt Dialog Box - lpszTitle
The string to be displayed in the title bar of the Prompt Dialog Box - lpszDefault
Initial default string of Prompt Dialog Box input box - bHidden
If set to True, input will be hidden (e.g. *****)
int xsh.Dialog.MessageBox(LPCTSTR lpszMessage, LPCTSTR lpszTitle, int nType)
Description
- Displays a message box with a variety of buttons and return values depending on user’s button selection
Return Values
- Refer to the nType parameter description below
Parameters
- lpszMessage
The string to be displayed in the Message Box - lpszTitle
The string to be displayed in the title bar of the Message Box - nType
Dictates button types. Refer to the table below
nType | Button | Return Value |
0 | OK | 1 |
1 | OK / Cancel | 1 / 2 |
2 | Abort / Retry / Ignore | 3 / 4 / 5 |
3 | Yes / No / Cancel | 6 / 7 / 2 |
4 | Yes / No | 6 / 7 |
5 | Retry / Cancel | 4 / 2 |
6 | Cancel / TryAgain / Continue | 2 / 10 / 11 |