Jonafla
Jonafla

Reputation: 21

Is there a Windows hook for when the internet is connected/disconnected?

I could do an endless timer checking IsInetOffline(), but I would prefer a hook callback that tells me when I plug/unplug the ethernet network cable or connect to wireless internet. Is there such a thing in the Windows API?

Upvotes: 2

Views: 918

Answers (3)

marcus
marcus

Reputation: 43

It's done with Win32 Shell Notifications (Explorer does that)
You can see here for code in C.

Upvotes: 0

shf301
shf301

Reputation: 31394

There may be a better way, but there is a NotifyAddrChange asynchronous function in the IP Helper Library that will create a notification when an IPv4 address changes.

Upvotes: 0

nitzmahone
nitzmahone

Reputation: 13940

If you're on .NET you can use the System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged event. It's using Winsock APIs under the covers if you need to do it without .NET (Reflector it if you want to know more), but it's some nasty async stuff in there- not a nice handy "call me when the network status changes".

Upvotes: 3

Related Questions