MSNdis_StatusMediaDisconnect and device Unique Name

883 Views Asked by At

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?

1

There are 1 best solutions below

1
On

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