求教大神一个telnet获取返回值的问题
代码如下,就是调取CMD实现telnet功能,我想获取程序结束后CMD命令下的返回值,试了很多方法都不管用。有哪位大神指点小弟一下啊 ,最好是能获取返回值放入文本框中显示,或者存成文件我再去分析也行。小弟新手,望高人请指点。Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim zl1 As String
Dim a As String
Dim username As String
Dim password As String
a = Left(Text2.Text, 2)
If a = "此处" Or a = "" Then
zl1 = "show onu unauthentication"
Else
zl1 = "show onu unauthentication epon-olt_" & Text2.Text
End If
username = olt.Text4.Text
password = olt.Text5.Text
Dim RetVal
RetVal = Shell("cmd /k " & "telnet xxx.xxx.xxx.xxx ", vbNormalFocus) '不关闭DOS窗口'运行bat文件,也可以是指令,由txtdosbat的内容决定.
Sleep 2000
SendKeys (username) '发送回车键
SendKeys ("{ENTER}") '发送回车键
SendKeys (password) '发送回车键
SendKeys ("{ENTER}") '发送回车键
SendKeys (zl1) '发送回车键
SendKeys ("{ENTER}") '发送回车键
End Sub