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

代码出处:How Can I Be Notified Any Time a Network Cable Gets Unplugged?

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. 从Win32程序的主函数WinMain中获取命令行参数
  2. NDS上的MD模拟器jEnesisDS
  3. C语言函数strcpy strncpy和strlcpy
  4. Switch 无法启动软件。 请在HOME菜单中再试一次。
  5. 3DS导出正版卡带存档并导入到CIA

留下回复