如何将Wshshell.sendkeys的结果保存到文本文件?

时间:2018-06-14 04:38:26

标签: vbscript wsh

我根本不是程序员,只是想从Windows平台为日常网络管理任务编写WSH脚本。我的脚本如下:

Option Explicit

Dim WshShell
Dim objFSO
Dim objFile
Dim strRhost

Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\test\swlist.txt", 1)

Do Until objFile.AtEndOfStream
    strRhost = objFile.ReadLine
    WshShell.Run "putty.exe -ssh " & Chr(34) & strRhost & Chr(34) & " -l admin -pw admin")
    WScript.Sleep 3000
    WshShell.SendKeys "enable{ENTER}"
    WScript.Sleep 100
    WshShell.SendKeys "password{ENTER}"
    WScript.Sleep 1000
    WshShell.SendKeys ("show clock{Enter}")
    WScript.Sleep 1500
    WshShell.SendKeys ("show version{Enter}")
    WScript.Sleep 1500
    WshShell.SendKeys ("show run{Enter}")
    WScript.Sleep 1500
    WshShell.SendKeys "exit{ENTER}"
    WScript.Sleep 1000
    WshShell.SendKeys "exit{ENTER}"
Loop

objFile.Close
WScript.Quit

以上脚本运行正常,但如何将所有结果的结果输出到屏幕和文本文件?

0 个答案:

没有答案