监视网络连接与断开,特殊情况下可能有点用,两个vbs脚本均来自微软官网
监视网络连接:
代码如下:
strcomputer = .
set objwmiservice = getobject(winmgmts:\\ & strcomputer & \root\wmi)
set colmonitoredevents = objwmiservice.execnotificationquery _
(select * from msndis_statusmediaconnect)
do while true
set strlatestevent = colmonitoredevents.nextevent
wscript.echo a network connection has been made:
wscript.echo strlatestevent.instancename, now
wscript.echo
loop
监视网络断开:
代码如下:
strcomputer = .
set objwmiservice = getobject(winmgmts:\\ & strcomputer & \root\wmi)
set colmonitoredevents = objwmiservice.execnotificationquery(select * from msndis_statusmediadisconnect)
do while true
set strlatestevent = colmonitoredevents.nextevent
wscript.echo a network connection has been lost:
wscript.echo strlatestevent.instancename, now
loop