VBS监视网络连接与断开的代码_vbs教程-查字典教程网
VBS监视网络连接与断开的代码
VBS监视网络连接与断开的代码
发布时间:2016-12-28 来源:查字典编辑
摘要:监视网络连接:复制代码代码如下:strComputer="."SetobjWMIService=GetObject("winmgmts:"&...

监视网络连接:

复制代码 代码如下:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & strComputer & "rootwmi")

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 & "rootwmi")

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

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新vbs学习
    热门vbs学习
    脚本专栏子分类