Article ID: 975425 - View products that this article applies to.
Windows Server 2008 R2 and Windows 7 introduce a new feature that is known as the trigger-start service. A Windows service can be registered as a trigger-start service by using the following methods:
Note This code sample that is described in this article is not meant for use in a production environment. It is provided only for illustration. This code sample is released under the terms of the Microsoft Public License (MS-PL).
Collapse this imageExpand this image
Download informationTo download this code sample, click the following link:
Technical overviewServices and background processes have great influence on the overall performance of the system. If you reduce the total number of services, you reduce the total power consumption and increase the overall stability of the system.
In Windows Server 2008 R2 and in Windows 7, the Service Control Manager is extended so that a service can be automatically started and stopped when a specific system event or a specific trigger occurs on the system. This mechanism is called a service trigger event. A service can register to start or to stop when a service trigger event occurs. This feature eliminates the need for services to start when the operating system starts. Therefore, this feature prevents a situation in which a service is started even though there is no work for the service to perform. For example, you can define a service trigger event that occurs when a device is enabled by a specified device interface class. Or, you can define a service trigger event that occurs when a particular firewall port is available. A service can also register for a custom service trigger event that is generated by an Event Tracing for Windows (ETW) provider.
This code sample shows how to create a trigger-start service that starts when a generic USB disk becomes available. The sample also shows how to create a trigger-start service that starts a service when the first IP address on the TCP/IP networking stack becomes available. The sample also shows how to create a trigger-stop service that stops a service when the last IP address on the TCP/IP networking stack becomes unavailable. These start and stop events are reported in the Application log.
Note For more information about how to create the sample application and how to deploy the sample application, see the Readme.txt file that is included in the download package.
LanguagesThis sample contains code samples in the following programming languages:
Collapse this tableExpand this table
What is All-In-One Code Framework?All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:
How to find more All-In-One Code Framework samplesTo find more All-In-One Code Framework samples, you can search for kbcodefx together with related keywords on support.microsoft.com. Or, you can simply click the following link:http://support.microsoft.com/search/default.aspx?query=kbcodefx
For more information about service trigger events, visit the following Microsoft Developer Network (MDSN) Web site:
http://msdn.microsoft.com/en-us/library/dd405513(VS.85).aspxFor more information about Windows SDK for Windows 7, visit the following Microsoft Web site:
http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=enFor more information about the Microsoft Public License, vist the following Web site:
Article ID: 975425 - Last Review: October 15, 2009 - Revision: 1.6