監視網絡連接:
復制代碼 代碼如下: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