3. Configuring the TriggerStartService Example
The TriggerStartService example begins with a
Windows service, so you'll select the Windows Service template in the
Windows folder of your favorite language, as shown in Figure 1.
Of course, the Windows Service template is only the starting point.
Now that you have a Windows Service project to use, you can begin configuring it. The following steps will get you started:
Right-click the Service1.CS entry in Solution Explorer and choose Rename from the Context menu. Change the filename to TriggerStartService.CS. The filename change is necessary to ensure you don't end up with a service named Service1 installed on the system.
Right-click the project entry in Solution Explorer and choose Add => Existing Item from the Context menu. You'll see an Add Existing Item dialog box.
Locate the ServiceNative.CS file on your hard drive, as shown in Figure 2. Adding this file provides P/Invoke support for the trigger-start features found in AdvAPI32.DLL.
Right-click
anywhere in the Design View window and choose Add Installer from the
Context menu. The installer makes it possible to install the service on
Windows later. You'll see several new files added to the project.
Finally, you'll see a ProjectInstaller Design View window open.
Right-click the ProjectInstaller.CS file entry in Solution Explorer and choose Rename from the Context menu. Rename the installer to TriggerStartServiceInstaller.CS.
Select serviceInstaller1 in the Design View window.
Change the (Name) property to TriggerStartServiceInstall, as shown in Figure 3.
Change the ServiceName property to TriggerStartService, as shown in Figure 3.
Select the serviceProcessInstaller1 entry in the Design View window.
Change the Account property to LocalSystem.