How to capture Internet connection event in Windows Task Scheduler?

I'm trying to create a simple task in Windows 7 that would run some script after every connection to the Internet. My gateway restart itself sometimes and I want to run that script every time Internet connection is restored.

In task creation wizard I choose that task should start "When a specific event is logged." But I don't know which one.


Solution 1:

I would use Task Scheduler to trigger the script on connection to a network, then use the script to confirm presence of the internet.

The Microsoft-Windows-NetworkProfile/Operational event log gets an event 10000 upon connection to a network, so you can use that to trigger your script.

Then at the beginning of the script, you could have something like:

ping 8.8.8.8 | find "Reply"
if errorlevel 1 goto :eof

# Your script