想通过vbs实现wincc端测试局域网内另外一台主机通信是否正常。从网上找了一段vbs ping代码,直接双击,运行成功。
但是放到wincc global s cript里面作为一个action,却无法执行。
我加入了一些msgbox,只能弹出OK0,下面好像就不执行了。
代码如下:
Option Explicit
Function action
MsgBox "ok"
Dim Shell, strCommand, strHost, ReturnCode
strHost = "www.google.com"
MsgBox "ok0"
Set Shell = ws cript.createObject("ws cript.shell")
MsgBox "ok1"
'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost
MsgBox "ok2"
'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)
MsgBox "ok3"
'0 = pingable, 1 = no response
If ReturnCode = 0 Then
ws cript.echo strHost & " is pingable"
Else
ws cript.echo strHost & " is not pingable"
End If
MsgBox "end"
End Function