5

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.

3
  • If you cannot quickly find the right logged event then why not disconnect your network and see what is logged (event viewer with a custom view of events in the last 10min will make that easier). But note: a network connection does not necessarily connect to the internet. Without some test tool that uses some heuristic to determine if a given network connection (one computer can have multiple) has connectivity. All you can do is trigger on a network connection and be prepared for no route to the internet.
    – Richard
    Jan 24, 2012 at 9:23
  • I just tried to capture all events during a period when I disconnected modem from gateway and reconnected it back. There was no events at all. But when I disconnected gateway some NetworkProfile events were captured. However, as you said, network connection does not guarantee presence of Internet connection.
    – Roman
    Jan 24, 2012 at 10:07
  • Your problem is when the gateway is disconnected there is nothing for the computer to detect directly (eg. no hardware change), so everything has to be indirect.
    – Richard
    Jan 25, 2012 at 8:31

1 Answer 1

7

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
1
  • Thanks, it works. Also, I added 30 sec delay, just to be sure.
    – Roman
    Jan 25, 2012 at 6:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .