View Single Post
  #11  
Old 09-15-2020, 08:50 AM
dlong dlong is offline
Registered User
 
Join Date: Dec 2015
Posts: 17
Quote:
Originally Posted by tnygren View Post
Hi Gamma,

This is possible using the scripting objects in SecureCRT.

I have provided an example VBscript below that will start a session and run a command.

The script does need the SecureCRT window to be already open but it sounded like you have already created that portion of the script.

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

' Modify the g_szCommand string below to send the command you want
' Modify the g_szSession to the session name that needs to be connected to
Dim g_szCommand, g_szPrompt, g_szSession

g_szSession = "redhat"
g_szCommand = "ps -auuux | grep $USER" & vbcr
g_szPrompt  = "->"

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

    ' Connect to the session

    crt.Session.Connect("/S " & chr(34) & g_szSession & chr(34))

    ' Issue the command that will generate the output that we are looking for
    crt.Screen.Send g_szCommand

    ' Wait for the command to finish (the prompt will appear when the command
    ' is done)
    crt.Screen.WaitForString(g_szPrompt)

    ' Now Quit SecureCRT
    crt.Sleep 250
    crt.Quit

End Sub
To start this script from the SecureCRT command line, just add the following to the SecureCRT command line:

SecureCRT.exe /Script <full path to script file\script name>

Was this the information that you needed?
Would anyone please point me in the right direction on syntax? I am trying both the shell.Run and Process.Start routines to effect a session, but my VB.NET error says 'file not found'.

Code:
  Dim shell
        shell = CreateObject("WScript.Shell")
        shell.Run("""C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe /Script H:\DH\secureCRT_Scripts\SESSION_FROM_VB_1.vbs")
. . . or . . .

Code:
Process.Start("C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe /Script H:\DH\secureCRT_Scripts\SESSION_FROM_VB_1.vbs")
. . . or . . .

Code:
Process.Start("cmd", """C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe /Script H:\DH\secureCRT_Scripts\SESSION_FROM_VB_1.vbs")

Last edited by dlong; 09-15-2020 at 08:52 AM.