#1
|
|||
|
|||
Default Settings...Login Script
I am trying to set my Default Settings > Login Script to look for a script file that matches the session name of teh device I am trying to connect to.
What I am doing is Options > Global Options > Default Session > Edit Default Settings... under Login Scripts, I have: C:\Program Files\SecureCRT\scripts\%S.vbs Where "%S" should be the session name of the device I am connecting to. But the app keeps telling me it can't find the file specifed. Is "%S" the correct variable to use to indicate Session Name? |
#2
|
|||
|
|||
Hi he204035,
It is not currently possible to use a variable like %S in the logon script path. I have created a feature request in our SecureCRT development database to add the ability to use a SecureCRT variable when defining a logon script. Should a future release of SecureCRT have this capability, we will post to this forum thread. If you would like to be notified directly, please complete and submit the form at the following location: Submit Feature Request |
#3
|
|||
|
|||
There is a possible work-around using ExecuteGlobal.
I've cobbled this example together from http://www.source-code.biz/snippets/vbscript/5.htm The downside is, if there's an error in the included script, you won't know which line since the error dialog will only point to the ExecuteGlobal line below. There's a few MessageBox calls that you'll want to remove/comment out. So basically, you would set this script in your Default Settings to execute the secondary scripts. Code:
#$language = "VBScript" #$interface = "1.0" ' From http://www.source-code.biz/snippets/vbscript/5.htm ' Set this to where your script files reside: strScriptPath = "e:\data\vandyke" Dim fso set fso = CreateObject("Scripting.FileSystemObject") Private Sub IncludeFile (ByVal RelativeFileName) ScriptDir = strScriptPath Rem -- Normally, it tries to get the name of the running script Rem -- and parses out the path to join with RelativeFileName Rem -- but WScript isn't available and I wasn't sure what to do about it, Rem -- so I made the strScriptPath global Rem Dim ScriptDir Rem ScriptDir = fso.GetParentFolderName(WShell.ScriptFullName) Dim FileName FileName = fso.BuildPath(ScriptDir,RelativeFileName) IncludeFileAbs FileName End Sub ' Includes a file in the global namespace of the current script. ' The file can contain any VBScript source code. ' The path of the file name must be specified absolute (or ' relative to the current directory). Private Sub IncludeFileAbs (ByVal FileName) Const ForReading = 1 crt.Dialog.MessageBox( "Opening file: " & FileName ) Dim f set f = fso.OpenTextFile(FileName,ForReading) Dim s s = f.ReadAll() Rem crt.Dialog.MessageBox( s ) ExecuteGlobal s End Sub ' Get the current session's path: strSessionPath = crt.Session.Path ' Get the session's parent folder -- as displayed in the Connect dialog: Set fso = CreateObject("Scripting.FileSystemObject") strParentFolder = fso.GetParentFolderName(strSessionPath) If strParentFolder = "" Then strParentFolder = "[\]" ' Get the current Session's name: strSessionName = fso.GetFileName(strSessionPath) 'Display the information in a msg box: crt.Dialog.MessageBox _ "Here are the details about this session's name & path:" & vbcrlf & _ String(60, "_") & vbcrlf & vbcrlf & _ "Name: " & vbtab & chr(34) & strSessionName & chr(34) & vbcrlf & _ String(60, "_") & vbcrlf & vbcrlf & _ "Path: " & vbtab & chr(34) & strSessionPath & chr(34) & vbcrlf & _ String(60, "_") & vbcrlf & vbcrlf & _ "Parent folder: " & vbtab & chr(34) & strParentFolder & chr(34) & _ vbcrlf & "(as displayed in Connect dialog)" IncludeFile strSessionName & ".vbs" |
#4
|
||||
|
||||
Quote:
%S refers to the Session configuration name itself, not the device name. %H would refer to the device (Host) name, which might more closely match what it is you're trying to accomplish -- assuming that I adequately understand what it is you are trying to accomplish. If you're using Quick Connect with the GUI (where the Save session option is not enabled) or other ad hoc connections (for example, launching SecureCRT from the command line using /SSH2 or /TELNET, etc), then it's the "Default" Session configuration that is used for connecting. Therefore, the script that SecureCRT would expect to run would be named "Default.vbs" (since that's the Session name of ad-hoc connections). However, if you're using Quick Connect with the GUI and the Save session option is enabled, it gets tricky because a session is actually saved based on the hostname. However, the session name might not be what you'd expect. For example, if you were to use Quick Connect to connect to 192.168.0.1, and you already had a session named 192.168.0.1, SecureCRT what do what you said -- save a session --, the name of the session would end up being "192.168.0.1 (1)", as in the first copy of that session. So using %S (if that's what you really need) would almost by necessity require that the "Save session" option in the Quick Connect dialog were turned off execpt for times where you're sure there isn't an existing session already. If, for example, I actually have a script named "Default.vbs" existing on my desktop, and I use the Quick Connect dialog with the "Save session" option enabled, I get the error you see -- because the session becomes a different name due to the "Save session" option being enabled. Based on your earlier description, and reading between the lines a bit, I suspect the substitution that would best fit your needs is %H (hostname). Does using %H work better for you? If not, and it appears that I haven't understood your question sufficiently, would you provide more details as to what you hope to accomplish? --Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
#5
|
|||
|
|||
![]()
I am using the COnnect dialog, not usually QuickCOnnect.
I have tried the %H but it still says it can;t find the file name. i was wondering, are there any registry or system settings that need to be configured for this to work? ![]() |
#6
|
|||
|
|||
Hi he204035,
Thanks for the update. I was incorrect when I initially said that you cannot use %S in a logon script path. You can, and you don't need to do anything special. I confirmed that in SecureCRT 6.7.1, I am able to define the following path for a logon script: Code:
c:\temp\%S.vbs Does this help to clarify how you can accomplish your goal? If not, what is the name of the session .ini file and the script? What version of SecureCRT are you using? |
![]() |
Thread Tools | |
Display Modes | |
|
|