Snippet Guides

New Windows Service Task

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.

Task naming


If the project is not open in Visual Studio, open it.


Add new item
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 fragment name
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.


Pick snippet
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 MPID
Enter the MPID and press tab.
Enter the the description part of the target class name. Press tab.


Enter target
Enter the target class. To use intellisense, press Backspace and then Ctrl+Space. Press tab.


Enter target
Press 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.

Press enter to stop editing.

Version: 1.0
Created: 2016-10-18, 14:53