Command tasks in Royal TS are very versatile and can be used for many different things. You can use them in context of a connection to quickly execute a command like ping while using the computer name/IP address of the selected computer(s) using “replacement tokens”. You can also use command tasks to be executed before you connect to a connection or after you disconnected from one by setting up the Connect Task and Disconnect Task configuration in the connection properties or the parent folder if you specified to use the settings inherited from the parent folder.

To explore command tasks, open the help document from within Royal TS (press F1 or by using the Help ribbon tab) and read the Command Task topics.

Injecting Values from your Context Connections

By using replacement tokens you can easily access all configuration settings of the context connection, such as computer name/IP as mentioned above but also things you put in one of the Custom Fields, for example. This makes the use of tasks more powerful and flexible.

Prompts

Sometimes you need to pass in values which are “more dynamic”. Values like session IDs or an often changed password/pin code which cannot really be stored in one of your objects because they change every minute or so (RSA SecureID tokens). While we are planning some advanced features around tasks and prompts in one of our next major releases, I just want to share a quick and effective way to implement prompts using out-of-the-box functionality in Windows.

Let’s assume a scenario where you need to establish a VPN tunnel with a VPN client but the password used in the VPN client command arguments is a dynamic, often changed pin code. For demonstration purposes I will create a command which prompts for input and then writes it to the console using the ECHO statement:

Let’s have a look at the command in more detail:

cmd.exe /v:on /c "set /p PWD=Password: & echo !PWD! & pause"

To test this, you can put the above line in a command prompt window and see the results.

Here’s what’s happening:

  • The Command we start in our task is cmd.exe
  • The /v:on argument tells the command prompt to expand environment variables at execution time using the ! character as delimiter (instead of %). Enter cmd.exe /? for more information.
  • With the /c argument we actually tell what command we want to execute
  • With the & character we chain multiple commands together
  • The first command in our chain is the SET statement: set /p PWD=Password:
    • /P allows you to prompt for a string and assign it to an environment variable
    • PWD is the environment variable name we use to store the prompted input string
    • Password: is the “prompt string” which is displayed in the command prompt
  • The second command in our chain is the ECHO command. This is just for demonstration. In a real world scenario this would be the command to open a VPN tunnel which needs the password submitted as argument. Something like: connect.exe /user:skoell /password:!PWD!
  • The third command in the chain is pause to stop execution and verify if our environment variable expansion works. This command in the chain should be removed in the final task definition.

If you put the command in a command prompt (cmd.exe) or just start the command task in Royal TS it will look like this:

Summary

When you replace the ECHO statement with the actual call to your VPN client application and assign this command task as a connect task in your connection properties, you can easily create simple prompts with no fancy add-on tools, etc.

Of course, this technique can also be used for lots of other stuff. You can chain commands together in this way to display some information (for example a list of tasks), prompt for the task ID to kill and kill the entered task. The sky is the limit…

cheers, Stefan

Previous Post Next Post