VanDyke Software

Scripting Examples

Index

Get Configuration Path

In your scripts, do you ever need to derive the configuration folder location where SecureCRT is loading/saving config data? These examples (Python and VBScript) show you how you can accomplish this in SecureCRT 7.2 and newer versions.

This technique leverages the cross-platform support that was introduced in SecureCRT version 7.2, providing a map between substitution variables and actual file system path locations. One such substitution is ${VDS_CONFIG_PATH}, which maps to the actual configuration folder in use by SecureCRT.

In this technique, our script code executes the following steps in order:

  1. Pick a session option name that we can use to return a path. It doesn't matter which one, but for this example, we choose to utilize the Upload Directory V2, which is used by SecureCRT to store the path where SecureCRT defaults to when browsing for files to upload (via X|Y|Zmodem transfers, for example).
  2. Read the current value of the Upload Directory V2, stashing it in a variable (so that we can restore the original value later).
  3. Set the value of the Upload Directory V2 option to ${VDS_CONFIG_PATH}.
  4. Save the config. This results in the ${VDS_CONFIG_PATH} substitution string literal being stored in the configuration for the session (Note: If the underlying session's .ini file is marked as Read-Only or otherwise cannot be written by the current user context, this approach will fail).
  5. Reload the session configuration.
  6. Get the value of the Upload Directory V2 session option. In the process of returning the value of this option, SecureCRT will convert the ${VDS_CONFIG_PATH} substitution variable into the actual path that SecureCRT is using for loading/saving configuration data.
  7. Set the Upload Directory V2 option to its original value.
  8. Save the config so that the changes are stored in the underlying .ini file.

So... which session is it that the script is manipulating in order to stash/set/read/restore the Upload Directory V2 option?

It so happens that it's the session that's active when the script is launched. If you don't have any active connections (SecureCRT has just been launched, and you don't have any tabs/tiles open to any hosts yet) or if you've been using ad hoc connections then it's the default session that is being manipulated. Watch the Default session YouTube video to learn more.

Example Scripts

GetConfigPath.py.txt (1.5 KB)
GetConfigPath.vbs.txt (1.6 KB)

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.