tags:

views:

104

answers:

1

Hello,

I'm using ManagementEventWatcher to watch the disconnection of network cable using System.Management.

ManagementEventWatcher with the WQL: SELECT * FROM MSNdis_StatusMediaDisconnect,
and the following method is fired, when EventArrived:

private void ServiceNetWorkStatusWmiDisconnected(object sender, EventArrivedEventArgs args)
{
    string instanceName = args.NewEvent.Properties["InstanceName"].Value as string;
    ServiceNetWorkStatusWmi = string.Format("Network disconnected ({0})", instanceName);
    Console.WriteLine(ServiceNetWorkStatusWmi);
}

The problem is:
I have 2 network interfaces, from the same manufacturer , and both case, the InstanceName has the same value and I can´t identify what network unplugged!

I have tried all properties from EventArrivedEventArgs, but they don´t have a constraint id for device... like an Device Id.

How can I find out witch network interface was unplugged?

A: 

Hi !

Have a look to the "Win32_NetworkAdapter.NetConnectionID". This is - at my machine [!!] - the excact same string you'll see in the network connections [control panel] and it should be the same value, apearing in "MSNdis_EnumerateAdapter.InstanceName=".

May be, this helps!?

br--mabra

mabra
Mabra, If I execute another WQL to Win32_NetworkAdapter I can view the NetConnectionId disconnected... but the problem is when MSNdis_StatusMediaDisconnect event arrives, I don´t have the AdapterId on object sender, neither on EventArrivedEventArgs!!!! that´s sucks!!! so I have to execute another WQL when event´s arrives to know the netadapter... I thinks it´s not good solution...
Guto Souza