監(jiān)視網(wǎng)絡(luò)連接與斷開,特殊情況下可能有點(diǎn)用,兩個vbs腳本均來自微軟官網(wǎng)
監(jiān)視網(wǎng)絡(luò)連接:
代碼如下:
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
監(jiān)視網(wǎng)絡(luò)斷開:
代碼如下:
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