# $language = "VBScript" # $interface = "1.0" ' OpenSessionLogFile.vbs ' Last Modified: 10 Apr, 2019 ' - Add support for /select argument to the script. If present, ' the log file itself will not be opened; instead, Windows ' Explorer will be opened, with the log file selected. ' ' Last Modified: 20 Nov, 2012 ' - Original revision ' ' Description ' This script opens the log file associated with a current session's ' configuration settings. ' ' Map a button on the button bar to run this script; see button bar video ' on the VanDykeSoftware YouTube channel on how to easily accomplish this: ' https://youtu.be/olyCcUWRimI "SecureCRT's Button Bar" ' https://youtu.be/qp82UWxGB8I "Button Bar Enhancements in SecureCRT" ' ' The session must have a log file name configured in session options in ' order for this script to operate successfully. ' ' Also, if logging isn't currently enabled and the log file name contains ' % substitutions for time and date, it may not be possible to determine ' the actual log file to open. However, in the 80% case, this script can be ' helpful in quickly opening the configured log file path for the currently- ' active, logging session. Set g_shell = CreateObject("WScript.Shell") g_strDlgTitle = "Open Session's Log File" Sub Main() ' Attempt to read the current log file name from session options strLogFileName = Trim(crt.Session.LogFileName) If crt.Session.Logging <> True Then If strLogFileName <> "" Then If crt.Dialog.MessageBox( _ "This session isn't currently logging!" & _ vbcrlf & vbcrlf & _ "Do you wish to open the log file configured in " & _ "session options (if any)?", _ g_strDlgTitle, _ vbYesNo) <> vbYes Then Exit Sub Else crt.Dialog.MessageBox _ "There is no log file name defined in session " & _ "options." & vbcrlf & vbcrlf & _ "This script requires a session configuration " & _ "that defines a log file path." & _ vbcrlf & vbcrlf & _ "Make sure that you have a log file name defined in " & _ """Options / Session Options, Terminal / Log File"" " & _ "category." Exit Sub End If 'If using SecureCRT version prior to 7.2, uncomment this next line: 'strSavedLogFileName = crt.Session.Config.GetOption("Log Filename") 'And comment out the following line: strSavedLogFileName = crt.Session.Config.GetOption("Log Filename V2") End If If strLogFileName = "" Then crt.Dialog.MessageBox _ "No log file is configured for this session!", _ g_strDlgTitle Exit Sub End If ' Determine if there are any % substitutions in the log file name. ' If so, we can't reliably determine the log file name because we ' don't know if we have the information available to make the ' necessary substitutions to get at the real log file name. If Instr(strSavedLogFileName, "%") > 0 Then ' Check to see if the file exists using the strLogFileName, whic ' will have substitutions made for us. If the log file doesn't ' exist, it means that there are time substitutions that prevent ' us from getting at the real name of the log file (that we were ' logging to earlier) Set g_fso = CreateObject("Scripting.FileSystemObject") If Not g_fso.FileExists(strLogFileName) Then crt.Dialog.MessageBox _ "Configured log file contains substitutions:" & vbcrlf & _ vbcrlf & _ strSavedLogFileName & vbcrlf & vbcrlf & _ "Make sure logging is currently active before you run " & _ "this script.", _ g_strDlgTitle Exit Sub End If End If bSelectFileInsteadOfOpen = False If crt.Arguments.Count > 0 Then strArg = LCase(crt.Arguments(0)) If strArg = "/select" Then bSelectFileInsteadOfOpen = True End If End If If bSelectFileInsteadOfOpen Then ' Just open Windows Explorer with the file selected: g_shell.Run "Explorer.exe /e,/select," & chr(34) & strLogFileName & chr(34) Else ' Open the file in the default handler for whatever type it is: g_shell.Run chr(34) & strLogFileName & chr(34) End If End Sub