Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-19-2006, 06:43 AM
Gamma Gamma is offline
Registered User
 
Join Date: Jan 2006
Posts: 4
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?
  #2  
Old 01-19-2006, 07:18 AM
Gamma Gamma is offline
Registered User
 
Join Date: Jan 2006
Posts: 4
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?
  #3  
Old 01-19-2006, 10:08 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
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?
__________________
Thanks,

Teresa

Teresa Nygren

Last edited by tnygren; 01-19-2006 at 02:29 PM.
  #4  
Old 01-20-2006, 05:45 AM
Gamma Gamma is offline
Registered User
 
Join Date: Jan 2006
Posts: 4
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.

Last edited by Gamma; 01-20-2006 at 05:50 AM.
  #5  
Old 01-20-2006, 10:18 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
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?
__________________
Thanks,

Teresa

Teresa Nygren
  #6  
Old 01-23-2006, 05:05 AM
Gamma Gamma is offline
Registered User
 
Join Date: Jan 2006
Posts: 4
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
  #7  
Old 01-23-2006, 08:54 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
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.
__________________
Thanks,

Teresa

Teresa Nygren
  #8  
Old 12-21-2009, 06:16 PM
Maureen's Avatar
Maureen Maureen is offline
VanDyke Product Director
 
Join Date: Feb 2004
Location: Albuquerque, NM
Posts: 1,591
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
  #9  
Old 02-03-2010, 01:52 PM
augustyn augustyn is offline
Registered User
 
Join Date: Feb 2009
Posts: 16
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.
  #10  
Old 02-03-2010, 04:16 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
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.
Attached Images
File Type: gif VRALib-API-Doc-Chm-scnsht.gif (39.2 KB, 482 views)
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]

Last edited by jdev; 02-03-2010 at 04:49 PM.
  #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.
  #12  
Old 09-15-2020, 09:27 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
Quote:
Originally Posted by dlong View Post
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""")
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
  #13  
Old 09-15-2020, 10:15 AM
dlong dlong is offline
Registered User
 
Join Date: Dec 2015
Posts: 17
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!

Last edited by dlong; 09-15-2020 at 10:22 AM.
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:36 AM.