Re: wbemtest and network adapter events

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 05/07/04


Date: Fri, 07 May 2004 10:58:18 +0200

Jon Hart wrote:

> I need to detect the connection and disconnection of network adapters.
> I have some code that I think does what I want, but Im not getting any
> events coming through when I unplug my cable ( the system tray sees
> the
> event ).
>
> So Im trying to use wbemtest to monitor the events, but nothing is
> coming through there either.
>
> This is what Im doing:
> (snip)
Hi

If it is network connection/disconnection you want to detect, you can use
MSNdis_StatusMediaConnect, here is a VBScript example that works for me:

Set colMonitoredEvents = GetObject("winmgmts:root\wmi")._
     ExecNotificationQuery("Select * from MSNdis_StatusMediaConnect")
Do
     Set strLatestEvent = colMonitoredEvents.NextEvent
     WScript.Echo "Connected! Do something here"
     ' 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! Do something here"
     ' 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/community/scriptcenter/default.mspx


Relevant Pages

  • Re: Adding a Key without overwriting what is already there
    ... registry value instead of creating yet another registry entry): ... On Error Goto 0 ... Exit For ' finished, exit the loop ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.win2000.registry)
  • Using open and pipe and regex - need some guidance please
    ... Am very new to Perl and has mostly done UNIX shell scripting. ... grep for things that I need to check, for example, ps -ef | grep ... close CAT; ...
    (perl.beginners)
  • Re: Fetching 2 NIC values only
    ... The Exit For is there because I don't know how to display 2 categories only. ... >> cards on the machine, so my goal is to fetch the the first and second cards ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Fetching 2 NIC values only
    ... for each blah blah ... Or - count the values you want and exit when you have as many as you need. ... >>> cards on the machine, so my goal is to fetch the the first and second ... >> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.win32.programmer.wmi)
  • Re: IE Toolbar Setting
    ... > unwanted toolbar line disappear by clicking on the display ... But when I exit IE and them come back for a new ... The Parasite Fight Quick Fix Protocol ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.win2000.general)