Vbscript 基于ping成功/失败显示消息的脚本

Vbscript 基于ping成功/失败显示消息的脚本,vbscript,Vbscript,现在,我有以下脚本正在运行: set WshShell = CreateObject("WScript.Shell") WshShell.run ("%COMSPEC% /c ipconfig /release"), 0, true WshShell.run ("%COMSPEC% /c ipconfig /renew"), 0, true PINGFlag = Not CBool(WshShell.run("ping -n 1 www.google.com",0,True)) If

现在,我有以下脚本正在运行:

set WshShell = CreateObject("WScript.Shell") 

WshShell.run ("%COMSPEC% /c ipconfig  /release"), 0, true
WshShell.run ("%COMSPEC% /c ipconfig  /renew"), 0, true

PINGFlag = Not CBool(WshShell.run("ping -n 1 www.google.com",0,True))
If PINGFlag = True Then
    MsgBox("ip release/renew was successful")
Else
    MsgBox("ip release/renew was not successful")
End If
我不太熟悉vbscript,但它似乎是显示弹出消息的最佳选择。我从网上找到的其他脚本中拼凑了这个脚本,因此我想了解更多关于它的工作原理:

我的问题是,我不太明白下面这一行是如何工作的:

PINGFlag = Not CBool(WshShell.run("ping -n 1 www.google.com",0,True))
它是如何确定PINGFlag的布尔值的

谢谢

.Run(…)返回已执行进程的退出代码/错误级别。CBool()对于0返回False,对于其他数字返回True。通过应用Not,“好”情况变为真,所有“坏”错误级别变为假

然后可以将If语句编码为“自然”:

If PINGFlag Then ' comparing boolean variables against boolean literals is just noise
    MsgBox "ip release/renew was successful" ' no () when calling a sub
Else
    MsgBox "ip release/renew was not successful"
End If

(%COMSPEC%/c ipconfig/release”)
(%COMSPEC%/c ipconfig/renew”)
周围不需要括号。请参阅我关于使用Visual Studio调试WSH脚本的说明。另外,请参阅关于
Run
方法。