Updated on Kisan Patel
To Get the services that depend on the current service, you need to use DependentServices property of ServiceController class.
class Program { static void Main(string[] args) { ServiceController scStateService = new ServiceController("Telephony"); Console.WriteLine("The Event Log Service status is currently set to {0}", scStateService.Status.ToString()); foreach (ServiceController sc in scStateService.DependentServices) { Console.WriteLine(scStateService.DisplayName + " is depended on by: " + sc.DisplayName); } Console.ReadKey(); } }
Output of the above program…
If you want to get the services that the current service does depend on, use below line of code:
foreach (ServiceController sc in scStateService.ServicesDependedOn) { Console.WriteLine(scStateService.DisplayName + " depends on: " + sc.DisplayName); }
Output of the above program…