Example of using Service Exists MSBuild task in Microsoft.Sdc.Tasks?


I'm trying to use the Microsoft.Sdc.Tasks.ServiceProcess.Exists to check whether or not a service exists. There is no example of using it in the documentation though. Anyone have one?


I've not actually used this in production myself, and I'm not sure which version you have (I have a copy of Release 2.1.3155.0) and according to the accompanying .chm help file the Task has the following properties:

<ul><li>DoesExist Returns TRUE if the service specified exists </li> <li>IsDisabled Returns TRUE if the service is disabled </li> <li>ServiceName The short name that identifies the service to the system.</li> </ul>

The ServiceName needs to be set to "The short name that identifies the service to the system, e.g. 'W3SVC'".

You might want to give it a try with a well known service (e.g. mssqlserver) and check the result of the other two properties (DoesExist/IsDisabled).

Update: Here's a sample (works):

Import the tasks, then call (e.g.)

< Microsoft.Sdc.Tasks.ServiceProcess.Exists ServiceName="Server"> < Output TaskParameter="DoesExist" PropertyName="Exists" /> < /Microsoft.Sdc.Tasks.ServiceProcess.Exists >

< Message Text="Service exists? $(Exists)" />


This is how we check if service exists, stop it if so, do something, and start service again (if there was one and it was started).

Helper target:

<target name="service_exists"> <script language="C#"> <references> <include name="System.ServiceProcess.dll" /> </references> <![CDATA[ public static void ScriptMain(Project project) { String serviceName = project.Properties["service.name"]; project.Properties["service.exists"] = "false"; project.Properties["service.running"] = "false"; System.ServiceProcess.ServiceController[] scServices; scServices = System.ServiceProcess.ServiceController.GetServices(); foreach (System.ServiceProcess.ServiceController scTemp in scServices) { if (String.Compare(scTemp.ServiceName.ToUpper(), serviceName.ToUpper()) == 0) { project.Properties["service.exists"] = "true"; project.Log(Level.Info, "Service " + serviceName + " exists"); if (scTemp.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running)) project.Properties["service.running"] = "true"; project.Log(Level.Info, "Service " + serviceName + " is running: " + project.Properties["service.running"]); return; } } project.Log(Level.Info, "Service " + serviceName + " doesn't exist"); } ]]> </script> </target>


<property name="service.name" value="Selection.Service" /> <call target="service_exists" /> <servicecontroller action="Stop" service="${service.name}" machine="${host}" timeout="60000" if="${service.exists}"/> <!-- Do something --> <servicecontroller action="Start" service="${service.name}" machine="${host}" timeout="60000" if="${bool::parse(service.exists) and bool::parse(service.running) == true}"/>

Hope I did not miss anything - our build admin keeps everything in one msbuild file which is now over 3600 lines :|


  • Impersonation failing for database connection
  • Trouble with the libPng.dylib from freetype 2.5.3
  • Can I use ASP.NET Session[] variable in an external DLL
  • Git branch switching does not change code folder files
  • Why do I get a message saying 1.not.found.as.a.resource?
  • QTreeView with fixed column widths
  • spring-data-redis Jackson serialization
  • Android: adding text color,background and font size to optionsmenu
  • Forward slash vs backward slash for file path in git bash
  • Getting specific color for specific value using JSON data
  • android check if file exists with case sensitivity?
  • Using loops in Jasmine (with injected service)
  • Unable to start a WebView from an AsyncTask
  • Arraylist of strings into one comma separated string
  • C# code can't “see” the methods in my C++ dll
  • All Event listing on specified date in Google Calender api (V3) in java?
  • Stop an element moving with padding on hover
  • Swift: UIView.animate works unexpectedly
  • getting the class name of an HTML tag using XPATH
  • How to create subsets of a single set of elements with XSLT?
  • How to run chrome.tabs.insertCSS from the background page on each page?
  • how to run a different select statement based on condition in Hive SQL
  • Runtime complexity of getting the length of a string in different representations
  • Problems to understand DXGI DirectX 11 Desktop Duplication to get a Buffer or Array
  • C++ STL stack pop operation giving segmentation fault
  • Conflicting declaration using constexpr and auto in C++11
  • Neo4j…how to get a visual representation of my data?
  • Python 3x- Compression Makes File Bigger :(
  • JavaScript Regex to Match Boundaries of Words with diacritics
  • Android: Unable to detect vertical plane
  • VSTS work items list through REST API
  • Debug `Unexpected end of JSON input Error` on content script
  • Bad automatic Triangulation with Mayavi for coloring a surface known only by its corner
  • Apple Mach-O Linker error (“duplicate symbol”)
  • How to get rgb from transparent pixel in js
  • Computing the discrete fourier transform of audio data with FFTW
  • Can someone explain this Java code (formatting the output using System.out.format) to me?
  • Using Service Component Runtime
  • Angular FormGroup won't update it's value immediately after patchValue or setValue
  • How to handle a codeigniter PDF generator