February 27th, 2020

How can I configure my Windows NT service to autostart when the system gains Internet access?

When configuring a Windows NT service, you can set the SERVICE_TRIGGER_INFO to include a SERVICE_TRIGGER that uses the SERVICE_TRIGGER_TYPE_IP_ADDRESS_AVAILABILITY trigger, so that it starts and stops based on whether the system has network access.

  Start when access gained Stop when access lost
dwTrigger SERVICE_TRIGGER_TYPE_IP_ADDRESS_AVAILABILITY
dwAction SERVICE_TRIGGER_ACTION_SERVICE_START SERVICE_TRIGGER_ACTION_SERVICE_STOP
pTriggerSubtype &NETWORK_MANAGER_FIRST_IP_ADDRESS_ARRIVAL_GUID &NETWORK_MANAGER_LAST_IP_ADDRESS_REMOVAL_GUID

Note that this will run your service when the system has an IP address, which is not the same as saying that the system has Internet access. It could be on an intranet, or it could be stuck behind a captive portal.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • David Walker

    So… can you have a service autostart when there is Internet access?