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.

  • 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 '12 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 '12 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 '12 at 8:31

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 | find "Reply"
if errorlevel 1 goto :eof

# Your script
  • Thanks, it works. Also, I added 30 sec delay, just to be sure. – Roman Jan 25 '12 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.