If you want to check if a specific NT Service is installed you will need to use the ServiceController class (from System.ServiceProcess). The first problem you will encounter is that the ServiceController has no static method, that would return a Boolean, specifying if the service is installed or not (e.g. ServiceController.IsInstalled(‘MyService’);) – so, to solve this you need to fetch the list of all installed services, using the static method ServiceController.GetServices(), which returns an array of ServiceController[], and then iterate thru all the elements to see if “MyService” is on that list. Now, this is not a problem, is just too much code for such a simple task. If you use LINQ things are simple: basically you will iterate thru the list, but in a much focused and simple way.
Check if a service is installed with ServiceController using LINQ
Leave a reply