VBS監(jiān)視網(wǎng)絡(luò)連接與斷開(kāi)的代碼

字號(hào):


    監(jiān)視網(wǎng)絡(luò)連接與斷開(kāi),特殊情況下可能有點(diǎn)用,兩個(gè)VBS腳本均來(lái)自微軟官網(wǎng)
    監(jiān)視網(wǎng)絡(luò)連接:
    代碼如下:
    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
    監(jiān)視網(wǎng)絡(luò)斷開(kāi):
    代碼如下:
    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