Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-06-2006, 06:40 PM
Aarc51 Aarc51 is offline
Registered User
 
Join Date: Aug 2006
Posts: 4
Is it possible to have excel open securecrt + run script?

I've written a script that parses the output from a show port status command on CATOS switches and puts the results in an excel workbook. I'm wondering if it's possible to somehow have excel open secure crt for me and run my script. Opening secure crt is easy enough but I'm not sure about the other part.
Reply With Quote
  #2  
Old 10-07-2006, 11:53 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
SecureCRT can be called with the /SCRIPT command line option so that SecureCRT runs a script when it starts. I'm not familiar enough with Excel programming to know how to create an external object and run it, but if you can create the object and perform object.run, then you should be able to run SecureCRT from your Excel application.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 04-23-2007, 10:15 PM
FuzzyBeanBag FuzzyBeanBag is offline
Registered User
 
Join Date: Apr 2007
Location: Washington
Posts: 2
Quote:
Originally Posted by Aarc51
I've written a script that parses the output from a show port status command on CATOS switches and puts the results in an excel workbook. I'm wondering if it's possible to somehow have excel open secure crt for me and run my script. Opening secure crt is easy enough but I'm not sure about the other part.
Aarc51 and or miked,

I know this post is a few months old but may come in handy for those curious of the same thing "I'm not sure about the other part".
The code listed below takes advantage of API to call Parent window of SecureCRT down to the chat window and allows you to run commands from an external app like Excel or Word or just using VB.
You can Copy and Paste the code below into a module in Excel and use the following code examples in a command button placed on a userform or just on a worksheet to send values or hard coded text/commands to SecureCRT.
Hope this is helpful.



Example: Telnet to a 2600 router:
*** Hardcoded In CommandButton***

Call CRT_SETTEXT("password")
Call CRT_BTNCLK
Call CRT_SETTEXT("enable")
Call CRT_BTNCLK
Call CRT_SETTEXT("password")
Call CRT_BTNCLK


*** Excel example In CommandButton***


Call CRT_SETTEXT(Sheet1.Range("A1").Value)
Call CRT_BTNCLK
Call CRT_SETTEXT("enable")
Call CRT_BTNCLK
Call CRT_SETTEXT(Sheet1.Range("A2").Value)
Call CRT_BTNCLK



***** COPY BELOW & PASTE INTO MODULE *****

Option Explicit


Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const WM_SETTEXT = &HC
Public Const BM_CLICK = &HF5

Public Function CRT_SETTEXT(TXT As String)
Dim E0012 As Long
Dim E0013 As Long
Dim E0014 As Long
Dim E0015 As Long
Dim CmdStr() As Byte

ReDim CmdStr(Len(TXT) + 1)

'*****************************************
'For what ever reason you must convert string to
'a ByteArray before sending text/commands to chatwindow
'*****************************************


CmdStr = StringToByteArray(TXT)

'******FIND SECURE CRT WINDOWS ***********
'Find SecureCRT 3.4.3 Main Window
'E0012 = FindWindow("Van Dyke Technologies - SecureCRT", vbNullString)
'*****************************************
'Find SecureCRT 5.5 Main Window

E0012 = FindWindow("VanDyke Software - SecureCRT", vbNullString)
'Find Dialog Window
E0013 = FindWindowEx(E0012, 0, "#32770", vbNullString)
'Find Edit/Textbox Window
E0014 = FindWindowEx(E0013, 0, "Edit", vbNullString)
'Set Text to Edit/Chat Window
E0015 = SendMessage(E0014, WM_SETTEXT, 0&, CmdStr(0))
'****************************************

End Function

Public Function CRT_BTNCLK()
Dim B0012 As Long
Dim B0013 As Long
Dim B0014 As Long
Dim B0015 As Long

'******FIND SECURE CRT WINDOWS ***********
'Find SecureCRT 3.4.3 Main Window
'B0012 = FindWindow("Van Dyke Technologies - SecureCRT", vbNullString)
'*****************************************
'Find SecureCRT 5.5 Main Window

B0012 = FindWindow("VanDyke Software - SecureCRT", vbNullString)
'Find Dialog Window
B0013 = FindWindowEx(B0012, 0, "#32770", vbNullString)
'Find Send Button
B0014 = FindWindowEx(B0013, 0, "Button", vbNullString)
'Click Send Button
B0015 = SendMessage(B0014, BM_CLICK, 0, ByVal 0&)
'****************************************

End Function


Public Function StringToByteArray(str As String) As Variant
Dim bray() As Byte
Dim cnt As Integer
Dim ln As Integer

ln = Len(str)

ReDim bray(ln)

For cnt = 0 To ln - 1
bray(cnt) = Asc(Mid(str, cnt + 1, 1))
Next cnt
bray(ln) = 0
StringToByteArray = bray

End Function
Reply With Quote
  #4  
Old 05-20-2010, 10:53 AM
Alan Walters Alan Walters is offline
Registered User
 
Join Date: May 2010
Posts: 2
Is it possible to have excel open securecrt + run script?

I just wanted to thank FuzzyBeanBag for contributing the VB snippet!

I was able to incorporate it into an existing Excel Macro I had created many years ago which imported rows into a different Telnet emulator (Personal WorkStation). The use of the SecureCRT Chat window to paste into is brilliant and was just the piece I was missing!

I now have a low speed data entry solution for importing repetitive data off a spreadsheet and using it to update applications running in the SecureCRT Telnet session. The less tech-savvy office drones now think I'm some kind of data magician! Even the more techy ones are suitably impressed!

Alan
Reply With Quote
  #5  
Old 08-07-2010, 04:34 PM
darkcloud7 darkcloud7 is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
It's Working Fine

Wow. I create a button in excel and joined the command. It's working fine. Now I wanted to implement a function thats after send the commad, capture the result and paste in the right side of the comand. Can you guys help me with this, please?
Reply With Quote
  #6  
Old 08-10-2010, 07:43 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi darkcloud7,

I am glad to hear that the button works. With regards to your next question, I am not sure what it is you want to accomplish.

What command are you trying to run?

Can you post a copy of the output of the command you want to run?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 08-10-2010 at 07:46 AM.
Reply With Quote
  #7  
Old 07-20-2011, 12:48 PM
tonhozi tonhozi is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
I think i know what darkcloud7 mean, i'm trying something similar.

I need to do a report from a server that i access with telnet.

For that i was using in vb the commands:

screenrow = crt.screen.CurrentRow -1
readline = crt.Screen.Get(screenrow, 4, screenrow, 80 )
items = Split( readline," ", -1 )

How can i do that in the excel?
Reply With Quote
  #8  
Old 07-20-2011, 12:57 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi tonhozi,

Thanks for the question. It seems like you want to be able to use the SecureCRT scripting API in an Excel VBA project. If this is what you want to do, it is not currently possible because the SecureCRT API is not exposed to third party programs.

Is this your goal, or do I not understand what you want to accomplish?

If I do not understand what you want to accomplish, can you provide more specific details?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #9  
Old 01-27-2017, 07:29 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 80
I see this thread is very old. However, if anyone stumbles on this, I have created a great deal of Excel-based code that wil use vba within Excel to call SecureCRT. That call uses an AdHoc connection and contains "/SCRIPT" as well as "/LOG" references. The Scripts within SecureCRT will use the copy buffer to return data to my Excel functions.

I can one-click a cell that has a device name and get a Form Control that will let me logon to that device. That logon will also prompt me for an RSA Token that will open the session.

I can Click to retrieve an entire router dump; although my code is using a jump host that contains applications that help me determine the device type as well as retrieving full device configs.
Reply With Quote
  #10  
Old 09-07-2017, 02:06 PM
cacman cacman is offline
Registered User
 
Join Date: Sep 2017
Posts: 2
Hello Rhudi,

Could you post an example of how you call SecureCRT from Excel/vba and pass commands in? I'm trying to doing something similar but not as complex and would appreciate any help.

Thanks.

Mike
Reply With Quote
  #11  
Old 09-07-2017, 03:22 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 751
Hi Mike,

Quote:
Originally Posted by cacman View Post
Could you post an example of how you call SecureCRT from Excel/vba and pass commands in? I'm trying to doing something similar but not as complex and would appreciate any help.
Not sure what Rhudi's code strategy is, but there are examples of integrating a launch of SecureCRT using information from an Excel Spreadsheet that can be found here:
Example: Integrating with Microsoft Excel
Pay particular attention to the last set of examples therein, one which launches a SecureCRT to connect to a host directly, and another which launches SecureCRT to first connect to a gateway/jump-host, and uses that as a firewall to connect to a secondary host behind the gateway/jump host.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
support@vandyke.com
http://www.vandyke.com/support
Reply With Quote
  #12  
Old 09-13-2017, 11:20 AM
cacman cacman is offline
Registered User
 
Join Date: Sep 2017
Posts: 2
Thanks Jake - one of the examples is exactly what I was looking for!

Mike Naglich
Reply With Quote
  #13  
Old 09-13-2017, 11:40 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 751
Quote:
Originally Posted by cacman View Post
Thanks Jake - one of the examples is exactly what I was looking for!
Nice when it works out like that!

Thanks for letting me know that you found something that you could use.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
support@vandyke.com
http://www.vandyke.com/support
Reply With Quote
Reply


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 06:53 AM.