【发布时间】:2016-05-09 00:45:23
【问题描述】:
我正在制作一个简单的脚本来 ping 地址并将结果保存在 txt 文件中。
目的仅仅是为了方便不知道如何操作的外行用户:
- 打开“运行”框;
- 打开cmd;
- ping 地址;
- 复制结果;
- 转至 txt 文件。
到目前为止,我已经制作了这个 .bat 文件,但我希望它在 vbs 上具有更多功能和更好的视觉效果。
.BAT 方法
@ECHO OFF
:LOOPSTART
time /T >> PingTest.txt
ping 1.1.1.1 -n 100 >> %userprofile%\Desktop\PingTest.txt
exit
GOTO LOOPSTART
.VBS 方法
Dim WshShell, i
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup "This program will run a connectivity test using PING", 5, "PING TEST!"
Dim strHost, strFile
strHost = "1.1.1.1"
strFile = "ping_test.txt"
PingCall strHost, strFile
Sub PingCall (strHost, outputfile)
Dim Output, Shell, strCommand, ReturnCode
Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile(outputfile, 8, True)
Set Shell = CreateObject("wscript.shell")
strCommand = "ping -n 100 " & strHost
While(True)
WshShell.Popup "Please, wait while test is being executed...", 1, "Test Running"
ReturnCode = Shell.Run(strCommand, 0, True)
Wend
End Sub
我遇到的问题 - 使用 VBS 脚本 -:
- 将ping结果保存到.txt文件;
- 显示一条消息,指示测试正在运行。我想要么 显示仍有多少数据包要发送或有一个盒子 在未完成时打开(“请稍等。这将关闭一次 测试已完成...");
就是这样。
我是不是太复杂了?
【问题讨论】:
标签: vbscript ping connectivity