从VBA运行Telnet会话 [英] Running a Telnet session from VBA
问题描述
如果可以使用MS WinSock控件(也请参阅在VBA中使用winsock )
更多资源:
如果没有,您可以使用 cmd.exe 和 SendKeys
或许:
免责声明:我从下面的第二个链接复制了下面的代码,并对VBA进行了一些修改。
sub telNETSc ript()
On Error Resume Next
Dim WshShell as object
set WshShell = CreateObject(WScript.Shell)
WshShell.runcmd.exe
WScript.Sleep 1000
'根据需要向窗口发送命令 - 需要自定义IP和命令
'步骤1 - Telnet到远程IP'
WshShell .SendKeystelnet xx.xx.xx.73 9999
WshShell.SendKeys({Enter})
WScript.Sleep 1000
'步骤2 - 发出命令与暂停'
WshShell.SendKeys({Enter})
WScript.Sleep 1000
WshShell.SendKeys5
WshShell.SendKeys({Enter})
WScript.Sleep 1000
'步骤3 - 退出命令窗口
WshShell.SendKeys退出
WshShell.SendKeys({Enter})
WScript 。Quit
end sub
SendKeys
不是最好的或最可靠的解决方案,但是当我12年前在我上一次工作的时候,我才能找到这一切。
更多信息:
Telnet& Excel - Microsoft.excel.programming
I have a VBA library that does FTP, I'd like to do telnet as well. At the moment I'm shelling out to a Perl script that does the telnet based on a text file, but I'd like to drive the telnet connection natively from within the VBA. Does anyone have any source for this? I don't want to use an add-in, I need the code to be self-contained.
If you can use the MS WinSock control (also see using winsock in VBA)
More resources:
MSDN Library: Using the Winsock Control
(Visual Basic) Winsock Control
if not, you could use cmd.exe and SendKeys
perhaps:
Disclaimer: I copied the below code from the second of the links below, and modified it slightly for VBA.
sub telNETScript()
On Error Resume Next
Dim WshShell as object
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet xx.xx.xx.73 9999"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "5"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Quit
end sub
SendKeys
is not the best or most reliable solution, but it was all I could find when I did this 12 years ago in my last job.
More info:
Telnet & Excel - Microsoft.excel.programming
How to automate Telnet commands using VBScript
这篇关于从VBA运行Telnet会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!