首页 > 编程 > VBScript > 正文

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

2020-07-26 11:47:45
字体:
来源:转载
供稿:网友

监视网络连接:

复制代码 代码如下:

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表