怎样用vbs实现ping一个ip地址 当time连续3次大于指定数值,就调用win系统声音报警。
怎样用vbs实现:ping一个输入的ip地址 当返回的time连续3次大于指定数值,就调用win系统声音或本目录中第一个声音文件进行报警。
请给出代码谢谢啦
[解决办法]
ip = "218.1.64.33"limit = 10n = 0For i = 1 To 30 Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & ip & "'") For Each objStatus in objPing ' WScript.Echo objStatus.ResponseTime If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Or objStatus.ResponseTime> limit Then n = n + 1 Else If n > 0 Then n = n - 1 End If Next If n >= 3 Then Exit For WScript.Sleep 1000NextIf n >=3 Then strSoundFile = "C:\Windows\Media\Notify.wav" Set objShell = CreateObject("Wscript.Shell") strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34) objShell.Run strCommand, 0, True Set objVoice = CreateObject("SAPI.SpVoice") objVoice.Speak "Ping Timeout"' 装中文 SpeecjSDK的话' objVoice.Speak "网络不正常"End If