VBS监视网络连接与断开的代码
程序员文章站
2022-07-06 12:58:00
监视网络连接:
复制代码 代码如下:strcomputer = "."
set objwmiservice = getobject("winmgmts:\\" & st...
监视网络连接:
复制代码 代码如下:
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