VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Example: Get Configuration Path (https://forums.vandyke.com/showthread.php?t=12861)

jdev 10-17-2017 03:21 PM

Example: Get Configuration Path
 
2 Attachment(s)
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.
  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.

Script examples for both Python and VBScript are included below.

--Jake


All times are GMT -6. The time now is 02:17 PM.