VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   VB.NET and SecureCRT (https://forums.vandyke.com/showthread.php?t=1220)

Gamma 01-19-2006 06:43 AM

VB.NET and SecureCRT
 
I am trying to open securecrt from VB.net. Is this a possibility? If yes, what references need adding and what script can be used?

Gamma 01-19-2006 07:18 AM

VB.Net and SecureCRT
 
Managed to open it using:

Dim shell
shell = CreateObject("WScript.Shell")
shell.Run("""C:\Program Files\SecureCRT\SecureCRT.EXE")

any ideas on how to connect to a session name and how to output commands to the securecrt window?

tnygren 01-19-2006 10:08 AM

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?

Gamma 01-20-2006 05:45 AM

Thank you Teresa

To give you some brief information, I am connecting to three terminals with three different session ids. The idea is to have VB.net open the correct session (and from there I know how to make each session run the relevant VB.script). The problem is how to control the SecureCRT application from VB.Net.

My question is:

if I want to open SecureCRT and connect to session XYZ, is there a command in VB.Net for that?

shell = CreateObject("WScript.Shell")
shell.run("""C:\Program Files\SecureCRT\SecureCRT.EXE")

Above opens SecureCRT but don't know how to connect to a specific Session from there. I could make SecureCRT always open one session (from Global settings), but it will not solve the problem when I need to connect to the other sessions.

The other alternative would have been to use shell.AppActivate and send keys to the window. Then I could make it run the script I want. But this too is not working.

Finally, you can add a COM reference in VB.Net (I do that for Excel and Reflections) - however I am unable to add SecureCRT (SSH2Core31 and vsh). This would have been the best option...

Any help would be most appreciated.

tnygren 01-20-2006 10:18 AM

Hi Gamma,

I think that I understand what it is that you are looking for.

Would a command line option to call a specific session help?

If so, SecureCRT does have a command line option that will allow you to open a session from the command line.

The syntax for this option is:

SecureCRT.exe /S <session name>

As for the COM call, it sound like you would like to be able to control SecureCRT from outside the GUI interface.

Is that correct?

If so, this is not currently possible.

We have had requests to allow this control but this is not yet on the development roadmap.

However. that could change in the future.

We can make a post here in this thread if control SecureCRT externally becomes and option.

Would you like to be notified if this option becomes available?

Gamma 01-23-2006 05:05 AM

Thanks so much Teresa

I got it working now using cmd from VB.net and then assigning different scripts to different sessions. I'm happy with that.

If in future you do get COM access, then please let me know.

Many thanks for all your help

John

tnygren 01-23-2006 08:54 AM

Hi John,

I'm glad that the script and information was helpful!

I have added this forum thread to our development database so that a post can be made here if the ability to control SecureCRT externally from a script is added.

If you would rather be contacted via email, please send an email to support@vandyke.com with the subject of ATTN: Teresa Forum Thread 1220.

Maureen 12-21-2009 06:16 PM

I wanted to let you know that an SSH2 API is available in the VanDyke ClientPack. This API allows the following types of operations to be scripted
through a COM or .NET interface:
  • Full control over SSH2 connections, including getting the ident string, specifying authentication methods and proxy/firewall settings, etc.
  • Sending a command to an SSH2 server and getting the output produced by the command
  • Tunneling/port forwarding
  • File transfers using SFTP
  • Remote file management, such as controlling file access or retrieving file attributes
  • Adding hostkeys to a hostkey datbase
  • Adding keys to the SSH2 authentication agent
At this time, the API does not support terminal emulation.

The API functions can be called from VBScript, C++, or any scripting platform that supports COM.

If you would be interested in trying the API, you can download the VandDyke Software ClientPack from the following web page.

http://www.vandyke.com/download/clie.../download.html

If you try it, please e-mail me at Maureen.Jett@vandyke.com to let me know how it works for you and if there's additional functionality you would like to see added.

Maureen

augustyn 02-03-2010 01:52 PM

Does anyone have any examples how to use this?

What object do we instantiate and what properties / methods are available?

The only documentation I see is for using the included command line utilities, which is a kludge vs using COM.

miked 02-03-2010 04:16 PM

1 Attachment(s)
With the current version of ClientPack (6.5 and newer) you'll find example scripts in a folder named Scripts, located in the ClientPack installation folder. The default location is:
C:\Program Files\VanDyke Software\ClientPack\Scripts
The Readme.txt file in the Scripts folder describes each of the following example scripts:
  • Example-AddHostkey.vbs
  • Example-Agent.vbs
  • Example-Connect.vbs
  • Example-RemoteFindFilesViaSFTP.vbs
  • Example-WriteToExcelFile.vbs
The example scripts also contain documentation in the form of comments.

Are these the kinds of examples you're looking for?

Also, the ClientPack 6.5.1 installation contains a ClientPack.chm file that includes the complete API documentation for VRALIB, as indicated in the attached screen-shot.

dlong 09-15-2020 08:50 AM

Quote:

Originally Posted by tnygren (Post 5376)
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")

jdev 09-15-2020 09:27 AM

Quote:

Originally Posted by dlong (Post 54014)
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")


Your quotations are unbalanced such that what you've entered wouldn't work from CMD.exe either.
  • You are missing an embedded/escaped quote after the path to SecureCRT.exe.
    As shown below, see the embedded/escaped quotes in red how they are matched up surrounding the path for SecureCRT.exe?
    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")

  • You should also consider embedding/escaping the path to your script file so that if you ever decide to change its name or location to something that has spaces in it, the embedded quotes will save you.
    As shown below, see the embedded/escaped quotes in purple how they are matched up surrounding the path for the script file?

    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""")


dlong 09-15-2020 10:15 AM

Thanks, Jake, that helped a lot. Now the program starts and the session is started as well, but because I use a login script for the session properties, I am getting an error message saying only one script can be run at a time.

Update: I was able to effect the auto-login to the session without the use of a script. Thanks!


All times are GMT -6. The time now is 04:39 AM.