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-20-2017, 12:24 PM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 27
Exclamation Excel Wscript VBA - Hostname lookup failed: host not found

Good day! I am trying to launch a SecureCRT session from a Microsoft Excel macro, but am running into an issue with regard to the session connecting successfully. It is opening SecureCRT, but then is spitting out an error:

"Hostname lookup failed: host not found"

Macro code:
Code:
Sub Launch_SecureCRT()
    
    ' Enter credentials in custom form
    Win_Login.Show
    strPassword = passkey
    strUsername = username
    
    'host and protocol
    strProtocol = "ssh2"
    strHostname = "host.com"
    
    ' Reference the SecureCRT script file to be run upon launch
    Set fso = CreateObject("Scripting.FileSystemObject")
    strScriptFile = "C:\Users\filepath\script.js" 


    ' Open SecureCRT and run script with login creds.
    Set objShell = CreateObject("wscript.shell")
    nResult = objShell.Run( _
        "SecureCRT /SCRIPT " & strScriptFile & _
        " /arg " & strHostname & _
        " /arg " & strUsername & _
        " /arg " & strProtocol & _
        " /PASSWORD " & strPassword, _
        5, True)

End Sub
Can someone please provide some insight? There is very little reference material for this out there.

Thank you for your time!
Reply With Quote
  #2  
Old 10-20-2017, 03:09 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi mschaafs,

It appears that the format of arguments being sent to the shell may not have been correct.

I had luck in launching sessions from an Excel macro using the below code:

Code:
Sub Launch_SecureCRT()

    strScriptFile = "C:\Users\filepath\script.js"
    strUsername = "username"
    strHostname = "host.com"
    strProtocol = "/SSH2"
    strPassword = "passkey"

    Call Shell("SecureCRT /SCRIPT " & strScriptFile & _
    " " & strProtocol & " /PASSWORD " & strPassword & _
    " " & strUsername & "@" & strHostname)

End Sub
Will something like this give you the behavior you're looking for?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-25-2017, 03:07 PM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 27
Talking Thank you!

That did the trick! Thank you so much!
Reply With Quote
  #4  
Old 10-25-2017, 03:16 PM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 27
Question Passing Args?

Ok... Hoping you can help me with one last thing... /ARG, I am trying to pass arguments to my script... and so I added another argument to pass in as:

Code:
    ' Open SecureCRT and run script with login creds.
    Set objShell = CreateObject("wscript.shell")
    nResult = objShell.Run( _
        "SecureCRT /SCRIPT " & strScriptFile & _
        " " & "/ARG " & strArgToPassIn & _
        " " & strProtocol & " /PASSWORD " & strPassword & _
        " " & strUsername & "@" & strHostname, 5, True)
On the VBScript example, it says this can be accessed via crt.Arguments(0), but I am using Javascript. So, I tried the bit below at the start of my script, but the message box showed no value. Any ideas?

Code:
var testvar = crt.Arguments[0];
crt.Dialog.MessageBox(testvar, "TESTVAR IS");
Reply With Quote
  #5  
Old 10-25-2017, 03:18 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi mschaafs,

I'm glad to hear that worked for you. Hopefully you have smooth sailing from here on out.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 10-25-2017, 03:39 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi mschaafs,

In my testing JavaScript uses the same format at VBScript.

Code:
var testvar = crt.Arguments(0);
crt.Dialog.MessageBox(testvar, "TESTVAR IS");
Does modifying your code in this way provide the desired behavior?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 10-26-2017, 08:28 AM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 27
Talking 2 for 2.

Fantastic... that worked. I should have thought to try that. :P Thank you again for your time!
Reply With Quote
  #8  
Old 10-26-2017, 09:30 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi mschaafs,

I'm glad I could help and that you're up and running.

Have a great rest of the day.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
excel to securecrt , hostname , wscript


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:01 AM.