I've been using a 3G wireless card for a while and every time I connect, my anti-virus fires up the updates.
I'm wondering what is the Win32 API set of functions that I can use to, either, get notified or query about the event of an Internet Connection coming up?
And is there already a set of ported headers for Delphi?
Look at InternetGetConnectedState in WinINet.
Some applications might also poll for a known server and not do anything until they get a valid connection.
I worked on a project to run a user's logon script whenever they connected our network over VPN. To do this, I wrote a helper unit that retrieves adapter info and stores it into a simple record.
I then setup up a registry notification, see here for how to do that in Delphi
The registry notification was on
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces
. This notification event fires every time Windows obtains a new IP address, or makes any type of change to an adapters connection information. When this event fired, I called the function (in the code below) to retrieve updated information about the adapter. I compared this new information to my previously recorded information...meaning I had to save the previous adapter info query in order to know if something had changed.Anyhow, here is my helper unit:
To use this unit from another unit, I created the following function, which populated a custom type called
TAdapterInfo
(declared in my main unit)://////////
On a completely side note, I also used this unit and almost exact same code to create a duplicate of
ifconfig -a
, which can be found on github. I mainly did it as an exercise in teaching myself how to accomplish this task.Here's a working example of how to use the helper unit. It is from a small project I wrote to emulate "ifconfig -a". This is a console application project.