View Single Post
  #3  
Old 04-07-2021, 08:00 AM
oliver366370 oliver366370 is offline
Registered User
 
Join Date: Sep 2018
Posts: 8
Quote:
Originally Posted by bgagnon View Post
Hi oliver366370,

How is OSCCurrent object defined?

How many connected tabs are there after you call ConnectInTab()?

It would probably be best if you posted the entire script. If there is sensitive data you don't want to post to the forums, please send a copy to support@vandyke.com and reference Attn Brenda - Forum Thread #14490 in the subject line. You can redact sensitive data but leave enough info we can determine the intent (ie: it's an IP or hostname).
Hi Brenda, thanks for getting back to me so quickly.

OSCCurrent is defined by setting it to a instance of the OpenSessionConfiguration, and handing it the he current session path via crt.Session.Path.
During my testing the open session is the only one open, which is replaced with the new tabbed session as it is disconnected in script.
The script is not too long and does not contain sensitive information so I have put it below.

Code:
#$language = "VBScript"
#$interface = "1.0"

crt.Screen.Synchronous = True

Sub Main()
    If crt.Arguments.Count <> 1 Then
        crt.Dialog.MessageBox("Incorrect number of arguments")
        Exit Sub
    End If

    Dim strCredentialPath, OSCCredential, OSCCurrent
    strCredentialPath = crt.Arguments.GetArg(0)
    
    On Error Resume Next
    Set OSCCredential = crt.OpenSessionConfiguration(strCredentialPath)
    Set OSCCurrent = crt.OpenSessionConfiguration(crt.Session.Path)
    
    If (OSCCurrent.GetOption("Username") <> OSCCredential.GetOption("Username")) Or (OSCCurrent.GetOption("Password") <> OSCCredential.GetOption("Password")) Or (OSCCurrent.GetOption("Session Password Saved") <> true) Then
        crt.Session.Disconnect
        Call OSCCurrent.SetOption("Username", OSCCredential.GetOption("Username"))
        Call OSCCurrent.SetOption("Password", OSCCredential.GetOption("Password"))
        Call OSCCurrent.SetOption("Session Password Saved", true)
        Call OSCCurrent.SetOption("Use Script File", false)
        OSCCurrent.ConnectInTab
        Call OSCCurrent.SetOption("Use Script File", true)
        OSCCurrent.Save(crt.Session.Path)
    End If
    
    If Err.Number <> 0 Then
        crt.Dialog.MessageBox("An error has occured while replicating the credentials from the template session")
        'crt.Dialog.MessageBox(Err.Description)
        Exit Sub
    End If
End Sub