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…
Give your task a name in the General tab, and then click Triggers and then click New.
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.
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.

Add some actions in the Actions tab and then click OK to finish making your task.
Test it out by disconnecting and then reconnecting your Internet.
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
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).
Test it out by disconnecting your network.
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.
29 Comments
Leave a Reply
Leave a Reply

Sameer Khan
didn’t work for me !!!
Jack Busch
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
Can you do the same but with the LAN cable is unplugged? Please it doesn’t work for me
Nam
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.
Linh Hoang
Just exactly what i’m looking for, works like charm. Thanks a lot Jack Busch for a priceless post.
BR/Linh
Tommy Smith
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?
Kumaran
It worked Fanstatic. I was searching for this Long time.
Thanks..Great Job
Amit
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?
Eric
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
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).
Eric
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.
Bryan
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
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
Forgot to mention:
EventID 50033 is recorded in Applications and Services > Microsoft > Windows > Dhcp-Client/Operational
Rob B
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
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
Thanks
Daan
Can you do the same if you disconnect your power adapter (laptop?)
ithrees
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!
Douglas
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?
Mario
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.
Manuel Mar
Thanks, work perfect!!!
Abdul
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)
Abu Gaci
Thanks, work perfect on windows 10!
Aero
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.
RP
This is running everytime that when I connect network.
How to setting for 1 time running not repeat .
Dimitri
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
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
Kostia
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