脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - VBS - VBS监视网络连接与断开的代码

VBS监视网络连接与断开的代码

2020-08-11 17:57VBS代码网 VBS

监视网络连接与断开,特殊情况下可能有点用,两个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

 

延伸 · 阅读

精彩推荐