0

Right now I have the following script working:

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

I'm not that familiar with vbscript but it seemed like my best option for displaying a popup message. I pieced together this script from others that I found online so I would like to know more about how it works:

My question is that I don't understand exactly how the following line is working:

PINGFlag = Not CBool(WshShell.run("ping -n 1 www.google.com",0,True))

What is it doing to determine the boolean value of PINGFlag?

Thanks!

rangers8905
  • 37
  • 1
  • 6
  • See my notes [here](http://stackoverflow.com/a/13802548/111794) about using Visual Studio to debug WSH scripts. Also, see [here](http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx) about the `Run` method. – Zev Spitz Jul 31 '13 at 14:48

1 Answers1

2

.Run(...) returns the exit code/ errorlevel of the process executed. CBool() returns False for 0 or True for other numbers. By applying Not, the 'good' case becomes True, all the 'bad' errorlevels False.

Then you can code the If statement 'naturally':

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
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • There is no need for parentheses around `("%COMSPEC% /c ipconfig /release")` or `("%COMSPEC% /c ipconfig /renew")` either – Zev Spitz Jul 31 '13 at 14:46