Skip to content
On this page

Script - Update hostname

This script will fetch the hostname of the device you're currently connected to and replace the tab name with the hostname

vb
crt.Screen.Synchronous = True

Sub Main
    Dim objTab
    Set objTab = crt.GetScriptTab
    strPrompt = GetPrompt()
    strPrompt = Replace(strPrompt, "#", "")
    strPrompt = Replace(strPrompt, "A:", "")
    strPrompt = Replace(strPrompt, "B:", "")
    objTab.Caption = strPrompt
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetPrompt()
    Do
        crt.Screen.Send vbCr
        Do
            bCursorMoved = crt.Screen.WaitForCursor(1)
        Loop Until bCursorMoved = False

        ' Once the cursor has stopped moving for about a second, we'll
        ' assume it's safe to start interacting with the remote system.
        ' Get the shell prompt so that we can know what to look for when
        ' determining if the command is completed. Won't work if the prompt
        ' is dynamic (e.g., changes according to current working folder, etc.).
        nRow = crt.Screen.CurrentRow
        strPrompt = crt.Screen.Get(nRow, _
            0, _
            nRow, _
            crt.Screen.CurrentColumn - 1)

        ' Loop until we actually see a line of text appear (the
        ' timeout for WaitForCursor above might not be enough
        ' for slower-responding hosts).
        strPrompt = Trim(strPrompt)
        If strPrompt <> "" Then Exit Do
    Loop

    GetPrompt = strPrompt
End Function