Reputation: 37
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!
Upvotes: 0
Views: 3417
Reputation: 38745
.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
Upvotes: 2