Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-05-2019, 02:19 AM
krypton179 krypton179 is offline
Registered User
 
Join Date: Apr 2019
Posts: 3
Sessions Directory Variable

Hi Experts,

could you please share a method to derive the active sessions directory path via python script.

Clearly I can look up the static path and add it as an entry within my script. But if the path has changed from the defaults, then I need a method to identify its new location.

Thanks
Reply With Quote
  #2  
Old 04-05-2019, 08:45 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
Hi krypton179,

What version of SecureCRT?

See Scripting / Script Objects Reference / Session Object. It is the Path property you will want to use, but as noted, it returns the entire path under the supplied Sessions folder. So you may need to parse the results depending on what data you are trying to get.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-08-2019, 03:39 AM
ogun ogun is offline
Registered User
 
Join Date: Sep 2013
Posts: 15
If you are looking for the full file system path, I use the following:

Code:
def get_config_path():
    """ Find path of SecureCRTs configuration """

    # This could be done using the config variable trick, this one has been proven to work on
    # many version of SecureCRT.
    if os.name == "nt":
        # We're on windows, use the registry
        import _winreg

        try:
            key = _winreg.OpenKey(
                _winreg.HKEY_CURRENT_USER, "SOFTWARE\\VanDyke\\SecureCRT"
            )
            config_path = _winreg.QueryValueEx(key, "Config Path")[0]
            _winreg.CloseKey(key)

            if "%" in config_path:
                config_path = _winreg.ExpandEnvironmentString(config_path)
            log.debug("Config path (Win): %s", config_path)
            return config_path
        except Exception as e:
            crt.Dialog.MessageBox(str(e))
    elif os.name == "posix":
        # We're on linux, read the config file
        try:
            import ConfigParser

            config_file = os.path.expanduser("~/.config/VanDyke/SecureCRT.conf")
            config = ConfigParser.ConfigParser()
            config.read(config_file)
            config_path = config.get("General", "Config%20Path")
            log.debug("Config path (Lin): %s", config_path)
            return config_path
        except Exception as e:
            crt.Dialog.MessageBox(str(e))
    else:
        crt.Dialog.MessageBox("Unknown os")
This will return the file system path of the configuration folder, just append "Sessions" to this you will get the path of the session files.
Not tested on versions below 8.0 but I see no reason why it shouldn't work.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 03:20 AM.