How-To

Windows Task Scheduler: Trigger an Event When Internet Connects or Disconnects

There are certain things that you might want to do every time your computer connects to the Internet or when your network connection is dropped; however, you might not always be around to do them.

Earlier, we showed you how to use Windows Task Scheduler to have your computer automatically wake or sleep at a certain time. Similar to that tip, you can set up Windows to perform tasks when a certain event occurs. One handy use of this feature is to trigger an event whenever your computer connects to the Internet or is disconnected from the Internet. You can use this to automatically send emails, save logs or do some other task when the Internet goes out and then comes back on. The key is to watch for two NetworkProfile event IDs: 10000 (connect) and 10001 (disconnect). Here’s how you use them.

Trigger an Event When Your Internet Connects or Disconnects with Task Scheduler

Launch Windows Task Scheduler from All Programs –> Accessories –> System Tools.

Click Action –> Create Task…

Trigger an Event on network connect

Give your task a name in the General tab, and then click Triggers and then click New.

display message on connect

In the “Begin the task” menu, choose “On an event.” Then, choose:

Log: Microsoft-Windows-NetworkProfile/Operational
Source: NetworkProfile
Event ID: 10000

The 10000 Event ID is logged when you connect to a network.

networkprofile event id 10000

Click OK.

Go to the Conditions tab. Here, you might want to uncheck “Start the task only if the computer is on AC power” (for laptops). You may also want to specify a network using the “Start only if the following network connection is available:” menu. This can be handy if you want to only run the task if you are on your work connection, or if you don’t want to run it while on a public network or something like that.

trigger an event on network connect or disconnect

Add some actions in the Actions tab and then click OK to finish making your task.

do something when computer connects to web

Test it out by disconnecting and then reconnecting your Internet.

automatically start program when computer connects to network

It worked!

To create an event that’s triggered when the network is disconnected, do everything the same except use 10001 for the Event ID.

Log: Microsoft-Windows-NetworkProfile/Operational
Source: NetworkProfile
Event ID: 10001

automatically run program when computer disconnects

You’ll also want to make sure that there aren’t any network connection conditions (since you won’t be connected to the Internet when this happens).

start program when computer connects or disconnects

Test it out by disconnecting your network.

display message or log event when computer loses internet connection

Obviously, this is just an example of what’s possible using Windows Task Schedule to watch for events and then doing something interesting… Some for good… and some for evil.

30 Comments

30 Comments

  1. Sameer Khan

    November 2, 2012 at 1:39 pm

    didn’t work for me !!!

    • Jack Busch

      November 4, 2012 at 5:16 pm

      hmm. are you on a wired or wireless connection? which version of windows are you running? Perhaps try tweaking some of the items in the Conditions tab. Start with no conditions and add them back to see which one may be causing the issue.

      • Christian

        October 31, 2019 at 8:56 am

        Can you do the same but with the LAN cable is unplugged? Please it doesn’t work for me

  2. Nam

    June 7, 2013 at 2:31 pm

    I tested this on a wireless connection with no dice. Win 7 Enterprise. Domain-joined machine. I check the event logs and I don’t see the one in question. Should be under Application logs according to what I’ve found.

  3. Linh Hoang

    March 21, 2014 at 2:36 am

    Just exactly what i’m looking for, works like charm. Thanks a lot Jack Busch for a priceless post.

    BR/Linh

  4. Tommy Smith

    June 6, 2014 at 7:48 am

    Hi,
    I’m trying to use this technique, but I’m wondering if it is possible to only have this trigger when the internet connection actually works? (like, not Limited access etc.) the reason being that I’m on one of those unsecured networks that require you “agree to the terms of service” before you can use it. Is there a seperate code for when the internet connects AND works?

  5. Kumaran

    December 24, 2015 at 2:57 pm

    It worked Fanstatic. I was searching for this Long time.
    Thanks..Great Job

  6. Amit

    January 25, 2016 at 8:11 am

    I’m looking for something similar to this… I don’t want the on-connection EVENT, I just want to trigger an event at a certain time IF i’m online… is it possible?

  7. Eric

    February 25, 2016 at 10:44 am

    Hello Jack,

    Thanks for this info.
    I’m looking to trigger the task when the network adapter is disabled / enabled (like from device manager). Which event can I use to detect it (Log / source / Event ID)?

    Thanks in advance.

    • Amit

      February 26, 2016 at 2:02 am

      I needed the same thing. Once you create the task on whatever trigger, check the Properties -> Conditions. In there at the bottom you should have a Network option that might do what you wants. (Info from Win10… not sure in other versions).

  8. Eric

    February 27, 2016 at 11:10 pm

    Amit,

    The option is also available in Win7. However, that’s not what I was looking for.
    I need the task to run whenever it detects that the network card has been disabled/enabled.

  9. Bryan

    November 25, 2016 at 12:46 pm

    Event ID 8001 for successful WiFi connection and 8003 for disconnect are being recorded in Applications and Services > Microsoft > Windows > WLAN-AutoConfig > Operational. For wired connection there are events 10000 (connected) & 10001 (disconnect) in Applications and Services > Microsoft > Windows > Network Profile Operational.

    • Eric

      November 30, 2016 at 8:43 am

      Bryan,

      Thank you for taking the time to check these events.

      I have already found those EventIDs by myself (I needed only the LAN events).

      There’s actually another very important EventID: 50033 (LAN interface added)
      Adding it to trigger my scheduled task solved my specific LAN problem completely.
      Cheers.

      • Eric

        November 30, 2016 at 8:46 am

        Forgot to mention:
        EventID 50033 is recorded in Applications and Services > Microsoft > Windows > Dhcp-Client/Operational

    • Rob B

      February 15, 2017 at 7:58 am

      Will 8003 work if the internet connection is lost but the network connection is not? I have a win 7 computer that drops wifi internet and only reconnects after a reboot. I am going to give it a try. Good article and thread. Thanks.

      • Rob B

        February 16, 2017 at 7:29 am

        An answer to my own question:

        8003 will not trigger in a Win 7 wifi machine that suffers from ‘No Network Access’ on a daily basis. In my case the computer drops internet but continues to be connected to the wifi network. I will look for other EventIDs. I am so close.

    • behzad

      May 8, 2022 at 12:27 am

      Thanks

  10. Daan

    August 24, 2017 at 2:54 pm

    Can you do the same if you disconnect your power adapter (laptop?)

  11. ithrees

    November 20, 2017 at 7:39 am

    Thanks for the post , everytime I connect to internet I wanted my laptop opens the chrome for me, it worked for me as I did all the steps except in the action section I changed to get my chrome open. thank you again!

  12. Douglas

    July 25, 2018 at 11:27 am

    Unfortunately, under Actions “Send and email” and “Display a message” are now both deprecated. “Start a program” is the only option. How do I write a script to send an email?

  13. Mario

    September 22, 2018 at 6:18 pm

    The original solution I was looking for does not work for me to detect when my VPN connection drops. The event 10001 does not log when VPN drops. However, by looking around I found that if I searched for the log Microsoft-Windows-DHCP Client Events/Operational, the source Dhcp-Client, and the Event ID 50002, I get what I want.

  14. Manuel Mar

    March 20, 2019 at 5:48 am

    Thanks, work perfect!!!

  15. Abdul

    April 9, 2019 at 3:40 am

    URGENT
    2 WIFI connections – one is internet another one is Limited access.

    the limited access (WIFI2) network frequently disconnects..

    How to config the task scheduler for this to connect automatically if it disconnects

    Note : Network conflict already done(Both wifi are working simultaneousy one for internet another one limited access for SFTP connection)

  16. Abu Gaci

    April 24, 2019 at 6:15 pm

    Thanks, work perfect on windows 10!

  17. Aero

    November 2, 2019 at 8:12 am

    It wasn’t working for me, but I finally figured out my problem: You don’t type in “NetworkProfile”, you select it from the dropdown. It looks the same, but it’s not. On the “Create Task” window, on the triggers tab, it will say “Source: Microsoft-Windows-NetworkProfile” instead of just the “NetworkProfile” you typed in.

    I found out by creating the task directly from eventviewer and comparing the differences, because that one worked.

    • Dart

      February 6, 2024 at 4:18 pm

      THANK YOU! it wasn’t working at all until I did this, you are a Savior.

  18. RP

    December 20, 2019 at 12:02 pm

    This is running everytime that when I connect network.
    How to setting for 1 time running not repeat .

    • Dimitri

      April 15, 2020 at 4:10 pm

      Same here. I need the PC to reboot when internet connection comes back. Unfortunately this creates an infinite reboot loop

      In case you’re wondering there’s an app running on an unattended machine. When we lose connection the app crashes. Since it’s a startup program a reboot fixes everything. Just need it to happen once though,

    • Mike Maddux

      May 12, 2020 at 5:50 am

      To only sent the notification for first logon of the
      day try something like this
      =======================================================
      REM filename start.bat — determine age of file “lastrun.txt” by converting access time to Georgian and comparing with the current time
      @echo off
      SET PARENT=%~dp0
      SETLOCAL ENABLEEXTENSIONS
      SETLOCAL ENABLEDELAYEDEXPANSION

      call:jdate tnow “%date%”
      for %%F in (lastrun.txt) do (
      call:ftime tfile “%%F”
      set /a diff=tnow-tfile
      )
      if /I !diff! GTR 0 call:SendEmail
      REM uncomment next line for testing
      REM echo.%%~nxF is !diff! days old

      REM resets file access date to current time and exits
      copy NUL lastrun.txt
      GOTO:eof

      REM Functions start below here

      :SendEmail
      REM use any good powershell script
      powershell -File “C:\….\sendemail.ps1”

      EXIT /b

      :ftime JD filename attr
      SETLOCAL
      set file=%~2
      set attr=%~3
      if not defined attr (call:jdate JD “- %~t2”
      ) ELSE (for /f %%a in (‘”dir %attr% /-c “%file%”|findstr “^^[0-9]””‘) do call:jdate JD “%%a”)
      ( ENDLOCAL & REM RETURN VALUES
      IF “%~1” NEQ “” (SET %~1=%JD%) ELSE (echo.%JD%)
      )
      EXIT /b

      :jdate JD DateStr
      SETLOCAL
      set DateStr=%~2&if “%~2″==”” set DateStr=%date%
      for /f “skip=1 tokens=2-4 delims=(-)” %%a in (‘”echo.|date”‘) do (
      for /f “tokens=1-3 delims=/.- ” %%A in (“%DateStr:* =%”) do (
      set %%a=%%A&set %%b=%%B&set %%c=%%C))
      set /a “yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100”
      set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
      ENDLOCAL & IF “%~1” NEQ “” (SET %~1=%JD%) ELSE (echo.%JD%)

      EXIT /b

  19. Kostia

    October 25, 2022 at 2:00 am

    can also use

    Application and services logs > Microsoft > Windows > Universal telemetry client > Operational log

    55 is Internet availability, true or false
    56 is network available, true or false

  20. Wayne

    May 16, 2023 at 11:48 am

    PERFECT! This is exactly what I needed….you are the MAN!

Leave a Reply

Your email address will not be published. Required fields are marked *

 

To Top