Before you begin: This snippet is used to create two task to start and stop a windows service. They are preconfigured to use the sc.exe command and send either a start or stop parameter together with the name of the service to be started/stopped. Default it uses a property called 'Name' on the target class.
The snippet is already partly configured with a name and an ID for the task. To learn more about how the name/ID is constructed consult the Management Pack Content document, section Workflow/Element naming.
If the project is not open in Visual Studio, open it.
Find the folder for the class that you want to create a task for. Right-click the folder and choose
Add\New Item.... In the list, select
Empty Management Pack Fragment.
Enter a name for the fragment. Since this is a specific, preconfigured, agent task it should be
StartStopServiceAgentTask. Click Add. The fragment is created and opened.
Right-click between the
<ManagementPackFragment> tags and select
Insert snippet. Choose
MPAuthoring\Agent Tasks\Windows Service\ and select the
Windows Service, Start/Stop snippet.
The code is inserted.
Enter the MPID and press
Enter the the description part of the target class name. Press
Enter the target class. To use intellisense, press
Backspace and then
Tab twice to accept the default command and working directory. Verify the name of the property on the target class which holds the service name. This is used as a parameter to the sc.exe command to start/stop the correct service.
enter to stop editing.