Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from Jan 24 '12 at 8:07

This question came from our site for system and network administrators.

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
up vote 5 down vote accepted

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
share|improve this answer
Thanks, it works. Also, I added 30 sec delay, just to be sure. – Roman Jan 25 '12 at 6:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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