How to realize the network connection state based on the disconnected VBS script
This article is to share with you about how to achieve network connection status based on disconnected VBS scripts. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Disconnect prompt
The code is as follows:
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
Wscript.Echo
Loop
Tips for establishing a connection
The code is as follows:
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
Thank you for reading! This is the end of the article on "how to achieve the network connection status based on the disconnected VBS script". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!