I can use PowerShell to do this fairly easily, but I am looking for a C# way to do this. With PS, I can use Get-Service to iterate over the collection and check collections in there called DependentServices and RequiredServices to get the list of the dependent and required services for a given service.
I’ve looked into the WMI model using the query “Select * from Win32_Service”, but this returns a collection of Win32_Service objects that does not seem to have the collections I am interested in. I feel like I am missing something here. I have looked around and tried various searches, but I’ve not turned up a C#-centric way of doing this.
I want to query a given service and get back the collections mentioned above (DependentServices and RequiredServices). Sorry if I missed the obvious, but I really have not been able to find relevant topics.
You can use the ServiceController class: