Detecting "Network cable plugged"

M

Markus Eßmayr

Hello!

I'm working on an application (a windows service) which should be able to
detect, if a network cable is plugged/unplugged. I know that there is a way
to query the state periodically but I guess that there is also a
"triggered"-way!
I just used Spy++ to trace the window messages received by Internet Explorer
and Lotus Notes while unplugging an replugging the cable.

The result: Internet Explorer receives 0x0410 (WM_USER + 16) on each event,
Lotus Notes receives nothing

Has anybody of you an idea, what is the best solution (or how Internet
Explorer is enabling this message)?

Note: I'm using C# and I'm forced not to use any P/Invoke (unmanaged code)

Thanks very much!

Max
 
J

Jason Hales

You could try subscribing to the MSNdis_StatusMediaDisconnect
management event in System.Management.

eventWatcher = new ManagementEventWatcher("root\\wmi", "SELECT * FROM
MSNdis_StatusMediaDisconnect");
eventWatcher.EventArrived+=new
EventArrivedEventHandler(eventWatcher_EventArrived);
eventWatcher.Start();

private void eventWatcher_EventArrived(object sender,
EventArrivedEventArgs e)
{
}

But I've never managed to get it to fire correctly?!?!?!?

The WMI extensions for Visual Studio Server Explorer are a handy add-in
for creating management code:
http://www.microsoft.com/downloads/...63-1253-4ea6-8599-68fb3ef77de1&DisplayLang=en

You might find this helpful too:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/monitordotnet.asp

Jason
 
J

Jim Hughes

VS2005 has the following event in ApplicationEvents when using a WinForms
app.

Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As
Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs)
Handles Me.NetworkAvailabilityChanged
Trace.WriteLine(e.IsNetworkAvailable)
End Sub

Haven't pursued it beyond that yet...
 
M

Markus Eßmayr

Thank you very much for the infos!
As it's a Windows Service without any form window, I can't use "Jim's way",
but maybe I will in another application. The way which Allan posted the link
to works very good for me!

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top