vbscript - Script that displays a message based on ping success/failure -
right have 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 msgbox("ip release/renew successful") else msgbox("ip release/renew not successful") end if
i'm not familiar vbscript seemed best option displaying popup message. pieced script others found online know more how works:
my question don't understand how following line working:
pingflag = not cbool(wshshell.run("ping -n 1 www.google.com",0,true))
what doing determine boolean value of pingflag?
thanks!
.run(...) returns exit code/ errorlevel of process executed. cbool() returns false 0 or true other numbers. applying not, 'good' case becomes true, 'bad' errorlevels false.
then can code if statement 'naturally':
if pingflag ' comparing boolean variables against boolean literals noise msgbox "ip release/renew successful" ' no () when calling sub else msgbox "ip release/renew not successful" end if
Comments
Post a Comment