SUPPORT > SECURECRT > IMPORTING CRT SESSIONS
Send us a question or comment

 

Send us your tip idea


 

Importing CRT™ Sessions to SecureCRT® for Windows®

Below is a tip on how to use a VBScript to import all of your CRT sessions into SecureCRT and automatically change protocol settings to SSH2.

Note: This tip is for use with SecureCRT for Windows.

Are you a CRT user who has recently upgraded or would like to upgrade to SecureCRT? Or does your company's security policy now enforce the use of SSH instead of Telnet?

If you're like some CRT users, you have many sessions configured for connecting to machines using Telnet. So how do you go about transferring all of your CRT sessions to SecureCRT? You can copy the sessions as they are from the CRT configuration folder to the SecureCRT configuration folder. But the protocol will remain as Telnet, and you need to use SSH2. If you have more than just a few sessions, manually changing all of the properties to SSH2 can take a lot of time.

Luckily, with the use of a VBScript, you can import all of your CRT sessions into SecureCRT and automatically change the protocol from a nonsecure one to a secure one such as SSH2 as part of the import process.

Below is an example VBScript code and instructions for use:

  1. Save the VBScript code to a file on your system and edit the code to suit your preferences. In
    particular, make sure that the g_szProtocol variable is set to the protocol you want each CRT session to be changed to during the copy process.

    For example, if you wish to set the protocol to SSH1 instead of SSH2 (this example script code specifies SSH2), set the g_szProtocol variable to ssh1.

  2. Once you have saved your changes to the VBScript code, start SecureCRT and choose Script -> Run. When the Select Script to Run dialog appears, browse to the location of the VBScript file that you have saved and choose Run.

    When the script completes, a summary message will appear, letting you know how many sessions were copied and if there were any duplicates. Note that if a session of the same name already exists in SecureCRT, the corresponding session from CRT will not be copied, and the existing session will be left unchanged.

#$language = "VBScript"
#$interface = "1.0"
' ImportCRTSessionsToSecureCRT.vbs
'
' Note: This script is intended to be run from with SecureCRT
'       (Script / Run).
'
' Description: Obtains the CRT configuration folder location from the
' registry and imports each session into the configuration folder for
' SecureCRT as indidcated in the registry.
'    - Creates folders if they do not already exist in the SecureCRT
'      config folder
'    - Modifies Protocol to SSH2 (or the value of g_szProtocol)
'    - Modifies the port to 22 (or the value of g_szPort _in Hex_).
'    - Ignores the default.ini file
'

Option Explicit

Dim g_fso, g_shell
Set g_fso   = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")

Dim g_szProtocol, g_szPort
g_szProtocol = "ssh2"

' Port string must be HEX
g_szPort = "00000016"

' The lines that we will be modifying in each .ini file
Dim g_szProtocolTag, g_szPortTag
g_szProtocolTag = "S:""Protocol Name""="
g_szPortTag = "D:""Port""="

Dim g_szCRTConfigFolderPath, g_szSecureCRTConfigFolderPath, szCrtReg
Dim g_szCRTSessions, g_szSecureCRTSessions, szSecureCRTReg

szCrtReg       = "HKCU\Software\VanDyke\CRT\Global\Config Path"
szSecureCRTReg = "HKCU\Software\VanDyke\SecureCRT\Global\Config Path"
g_szCRTConfigFolderPath = g_shell.RegRead(szCrtReg)
g_szSecureCRTConfigFolderPath = g_shell.RegRead(szSecureCRTReg)

Dim g_szSessionsAlreadyThere, g_nMovedCount, g_nFoldersCreated
g_szSessionsAlreadyThere = ""
g_nMovedCount = 0
g_nFoldersCreated = 0

Const ForReading = 1

' If running this from outside SecureCRT:
' - comment out the first two lines of this file
' - remove the comment from the line below.
' - change all instances of "crt.Sleep" to "WScript.Sleep"
'Main

Dim g_szTitle
g_szTitle = "Import CRT Sessions To SecureCRT Script"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()

    ' Get a valid CRT configuration folder
    While Not g_fso.FolderExists(g_szCRTSessions)
        g_szCRTSessions = InputBox( _
            "Please enter the location of the CRT config folder:", _
            g_szTitle, _
            g_szCRTConfigFolderPath)

        If g_szCRTSessions = "" Then Exit Sub

        If Not g_fso.FolderExists(g_szCRTSessions & "\Sessions") Then
            MsgBox "The folder specified does not contain the" & vbcrlf & _
                   "required ""Sessions"" subfolder:" & vbcrlf & _
                    chr(9) & g_szCRTSessions
            g_szCRTConfigFolderPath = g_szCRTSessions
            g_szCRTSessions = ""
        End If
    Wend

    ' Get a valid SecureCRT Configuration folder
    While Not g_fso.FolderExists(g_szSecureCRTSessions)
        g_szSecureCRTSessions = InputBox( _
            "Please enter the location of the SecureCRT config folder:", _
            g_szTitle, _
            g_szSecureCRTConfigFolderPath)

        If g_szSecureCRTSessions = "" Then Exit Sub

        If not g_fso.FolderExists(g_szSecureCRTSessions & "\Sessions") Then
            MsgBox "The folder specified does not contain the " & vbcrlf & _
                   "required ""Sessions"" subfolder:" & vbcrlf & _
                    chr(9) & g_szSecureCRTSessions
            g_szSecureCRTConfigFolderPath = g_szSecureCRTSessions
            g_szSecureCRTSessions = ""
        End If
    Wend

    g_szCRTSessions = g_szCRTSessions & "\Sessions"
    g_szSecureCRTSessions = g_szSecureCRTSessions & "\Sessions"

    ' This is where all of the importing takes place.
    ProcessFolder g_szCRTSessions, g_szSecureCRTSessions

    Dim szStatusMsg
    szStatusMsg = "Moved " & g_nMovedCount & " sessions" & vbcrlf & vbcrlf & _
                  "     From: " & chr(9) & g_szCRTSessions & vbcrlf & _
                  "     To: " & chr(9) & g_szSecureCRTSessions & vbcrlf & _
                  vbcrlf & _
                  "In the process, we created " & g_nFoldersCreated & _
                  " new folders in the SecureCRT Sessions hierarchy."

    If g_szSessionsAlreadyThere <> "" Then
        szStatusMsg = szStatusMsg & vbcrlf & _
            vbcrlf & "======" & vbcrlf & _
            "The following sessions were not copied from the CRT" & _
            " config because they" & vbcrlf & _
            "already existed in SecureCRT:" & vbcrlf & _
            g_szSessionsAlreadyThere
    End If

    MsgBox szStatusMsg

    Set g_fso = Nothing
    Set g_shell = Nothing

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Helper Methods and Functions
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub ProcessFolder(szCRTFolderPath, szSecureCRTFolderPath)
' Recursive routine that copies all contents of the szCRTFolderPath
' to the szSecureCRTFolderPath

    Dim objCRTFolder, objSecureCRTFolder
    Set objCRTFolder = g_fso.GetFolder(szCRTFolderPath)

    ' Create all of the folders in the current location
    Dim objSubFolder
    For Each objSubFolder in objCRTFolder.SubFolders
        Dim szCurTargetFolder
        szCurTargetFolder = szSecureCRTFolderPath & "\" & objSubFolder.Name
        If Not g_fso.FolderExists(szCurTargetFolder) Then
            g_fso.CreateFolder szCurTargetFolder
            g_nFoldersCreated = g_nFoldersCreated + 1
        End If

        ProcessFolder objSubFolder.Path, szCurTargetFolder
    Next

    ' Copy and modify all of the sessions in the current location
    Dim objFile
    For Each objFile in objCRTFolder.Files
        ' Only copy the file if it's not __FolderData__.ini or default.ini
        ' and if it doesn't already exist.

        If objFile.Name <> "__FolderData__.ini" And _
           objFile.Name <> "Default.ini" Then

            Dim szTargetSession
            szTargetSession = szSecureCRTFolderPath & "\" & objFile.Name

            If Not g_fso.FileExists(szTargetSession) Then

                ' Now make the config changes
                Dim objSrc, objDst, szCurrentLine, szText
                Set objSrc = objFile.OpenAsTextStream(ForReading)
                Set objDst = g_fso.CreateTextFile(szTargetSession)

                While Not objSrc.AtEndOfStream
                    szCurrentLine = objSrc.ReadLine

                    If InStr(szCurrentLine, g_szProtocolTag) > 0 Then
                        szCurrentLine = g_szProtocolTag & g_szProtocol
                    ElseIf InStr(szCurrentLine, g_szPortTag) > 0 Then
                        szCurrentLine = g_szPortTag & g_szPort
                    End If

                    szText = szText & szCurrentLine & vbcrlf
                Wend

                objDst.Write szText
                objDst.Close

                g_nMovedCount = g_nMovedCount + 1

            Else
                If Not InStr(g_szSessionsAlreadyThere, objFile.Name) > 0 Then
                    g_szSessionsAlreadyThere = g_szSessionsAlreadyThere & _
                    vbcrlf & chr(9) & objFile.Name
                End If
            End If ' Not g_fso.FileExists(szCurTargetSession)...
        End If ' objFile.Name <> "__FolderData__.ini" , etc...
    Next
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function Continue(szMsg)
    Continue = True
    crt.Sleep 200
    If MsgBox(szMsg, vbYesno, g_szTitle) <> vbYes Then Continue = False
    crt.Sleep 400
End Function

 

Was this information helpful?
Yes No
Thank you!
Send your comments and questions to VanDyke Software Support,
or join the discussion in the VanDyke Software Forums.
Can't find the answer you're looking for?
Ask VanDyke Software Support directly
and we will get back to you as soon as possible.