vbs监视网络连接的代码:
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
vbs监视网络断开的代码:
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还是很好用的,回想当年搞asp时,经常用到这些,用vbs监视网络的连接与断开状态,个人感觉还是不错的,经济实用啊。