VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "ThisWorkbook" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = True Sub ConnectAndSendCommands() Dim strProtocol As String Dim strHostname As String Dim strUsername As String Dim strFirewallSession As String Dim strEnablePass As String Dim objRow As Range Set objRow = Selection.Rows(1) strProtocol = Cells(objRow.Row, 2) strHostname = Cells(objRow.Row, 1) strUsername = Cells(objRow.Row, 3) strPassword = Cells(objRow.Row, 4) strFirewallSession = Cells(objRow.Row, 5) strEnablePass = Cells(objRow.Row, 6) Set fso = CreateObject("Scripting.FileSystemObject") Dim strTempPath As String strTempPath = fso.GetSpecialFolder(2) Dim strScriptCodeTelnet As String Dim strScriptCodeSSH As String Dim strScriptFile As String Dim strScriptCode As String strScriptCodeTelnet = "" & _ "strUsername = crt.Arguments(0)" & vbCrLf & _ "strPassword = crt.Arguments(1)" & vbCrLf & _ "strEnablePwd = crt.Arguments(2)" & vbCrLf & _ vbCrLf & _ "crt.Screen.Synchronous = True" & vbCrLf & _ "crt.Screen.WaitForStrings(""ogin:"", ""ername:"")" & vbCrLf & _ "crt.Screen.Send(strUsername & vbcr)" & vbCrLf & _ "crt.Screen.WaitForString(""ssword:"")" & vbCrLf & _ "crt.Screen.Send(strPassword & vbcr)" & vbCrLf & _ "crt.Screen.WaitForString("">"")" & vbCrLf & _ "crt.Screen.Send(""enable"" & vbcr)" & vbCrLf & _ "crt.Screen.WaitForString(""ssword:"")" & vbCrLf & _ "crt.Screen.Send(strEnablePwd & vbcr)" & vbCrLf & _ "crt.Screen.WaitForString(""#"")" & vbCrLf & _ "Set objFSO = CreateObject(""Scripting.FileSystemObject"")" & vbCrLf & _ "objFSO.DeleteFile(crt.ScriptFullName)" & vbCrLf & _ "" strScriptCodeSSH = "" & _ "strEnablePwd = crt.Arguments(0)" & vbCrLf & _ vbCrLf & _ "crt.Screen.Synchronous = True" & vbCrLf & _ "crt.Screen.WaitForString("">"")" & vbCrLf & _ "crt.Screen.Send(""enable"" & vbcr)" & vbCrLf & _ "crt.Screen.WaitForString(""ssword:"")" & vbCrLf & _ "crt.Screen.Send(strEnablePwd & vbcr)" & vbCrLf & _ "crt.Screen.WaitForString(""#"")" & vbCrLf & _ "Set objFSO = CreateObject(""Scripting.FileSystemObject"")" & vbCrLf & _ "objFSO.DeleteFile(crt.ScriptFullName)" & vbCrLf & _ "" Select Case UCase(strProtocol) Case "TELNET" strScriptFile = strTempPath & "\ScrtXLSscript_Telnet.vbs" strScriptCode = strScriptCodeTelnet strArgs = " /Script """ & strScriptFile & """ /arg " & strUsername & " /arg """ & strPassword & """ /arg """ & strEnablePass & """" & " /TELNET " & strHostname Case "SSH2" strScriptFile = strTempPath & "\ScrtXLSscript_SSH.vbs" strScriptCode = strScriptCodeSSH strArgs = " /Script """ & strScriptFile & """ /arg """ & strEnablePass & """" & " /SSH2 /L " & strUsername & " /PASSWORD """ & strPassword & """ " & strHostname Case "SSH1" strScriptFile = strTempPath & "\ScrtXLSscript_SSH.vbs" strScriptCode = strScriptCodeSSH strArgs = " /Script """ & strScriptFile & """ /arg """ & strEnablePass & """" & "/SSH1 /L " & strUsername & " /PASSWORD """ & strPassword & """ " & strHostname Case Else MsgBox ("Unsupported protocol: " & strProtocol) Exit Sub End Select If strFirewallSession <> "" Then strArgs = "/FIREWALL=Session:""" & strFirewallSession & """ " & strArgs End If Set objFile = fso.OpenTextFile(strScriptFile, 2, True) objFile.Write strScriptCode objFile.Close Set objShell = CreateObject("wscript.shell") nResult = objShell.Run( _ "SecureCRT /T " & strArgs, _ 5, True) End Sub