Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Execute script automatically upon network connection or disconnect

14 views
Skip to first unread message

Tim Richardson

unread,
Dec 4, 2003, 2:14:32 PM12/4/03
to
Using the Windows scripting host, can I have scripts executed
automatically when the computer establishes a TCP/IP network
connection (when a LAN cable is plugged in to a notebook)? Windows XP
Professional. In other words, are their hooks that can call scripts
when certain OS events happen? Or is there a general purpose service
that does this?

regards,
Tim

Torgeir Bakken (MVP)

unread,
Dec 4, 2003, 5:13:11 PM12/4/03
to
Tim Richardson wrote:

Hi

For all network connection events:

Set colMonitoredEvents = GetObject("winmgmts:root\wmi")._
ExecNotificationQuery("Select * from MSNdis_StatusMediaConnect")
Do
Set strLatestEvent = colMonitoredEvents.NextEvent
WScript.Echo "Connected!"
' enable the line below if you want to exit after the first event.
'Exit Do
Loop


If you want to check a specific adapter, use e.g. a select on the InstanceName
of the adapter:

Set colMonitoredEvents = GetObject("winmgmts:root\wmi")._
ExecNotificationQuery("Select * from MSNdis_StatusMediaConnect" _
& " WHERE InstanceName = '3Com 10/100 Mini PCI Ethernet Adapter'")
Do
Set strLatestEvent = colMonitoredEvents.NextEvent
WScript.Echo "Connected!"
' enable the line below if you want to exit after the first event.
'Exit Do
Loop

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Tim Richardson

unread,
Dec 17, 2003, 1:00:02 PM12/17/03
to
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message news:<3FCFB177...@hydro.com>...


thanks,

Tim

0 new messages